Win8.1 COCOS2D-X 3.4 environment construction, win8.1cocos2d-x

Source: Internet
Author: User

Win8.1 COCOS2D-X 3.4 environment construction, win8.1cocos2d-x

Cocos2dx_3.4 build the development environment and compile it into an APK


Step 1: download the following information: (set up the windows 64-bit system environment)








Two important commands:

Cocos new-p com. game. simple-l cpp-d e: \ simple //Create a project

Cocoscompile-p android // compile to apk

Step 2 install Python

Many tools in cocos2d-x use Python, so we need to install the Python environment first

You need to download Python 2.x. Do not download version 3.x

You can use the default installation method when installing python. However, after installing python, You need to configure environment variables.

Choose my computer (right-click)> Properties> advanced system Settings> Advanced Tab> environment variables> system variables, and find the Path variable, add the environment variable pointing to Python in the value. The format is [Python installation path]. For example, the environment variable I installed on drive C is added to C: \ Python27;

After the configuration is complete, log out and then log on to the system environment variable to make the configuration take effect.




Note: After Python is installed, it is configured in path, but it will still prompt that Python is not an internal command. This is the case for me. You need to enter the command box every time you run cmd, when executing commands such as cocos new or python, you must manually execute set PATH = % PATH %; C: \ Python27 (my installation in the C root directory depends on your installation ). Then you can execute commands such as cocos as follows:


Run-> cmd

InputSet PATH = % PATH %; C: \ Python27 

Next, enter python in the current cmd to run the command. if the version information is displayed, the installation is successful.


Step 3: configure the cocos2d Environment

Go to the cocos2d-x folder and find the setup. py file, run, the Console appears as follows


Since the Android environment is not configured now, you just need to press enter, this python script will help us set the environment variables required for the cocos2d-x to run. Continue to log out ...... Log On again ...... To take effect

After all this is configured, run CMD to run the cocos command, 1 to check whether the entire development environment is successfully set up, and 2 to familiarize yourself with the command line, if the settings are correct, the following page appears:

Here we can see that the cocos. py script can execute four commands. The role of each command is clearly described.




Step 3: Use the new command to create a project


For example, if you want to create a project named simple, you can writeCocosnew-p com. game. simple-l cpp-d e: \ simpleRun this command to generate a project named simple in the root directory of the E disk. If the following information is displayed, the creation is successful.


In this case, you can use VS2012 to open the sln project file in proj. win32 for encoding and debugging.


If we want to run the project we just generated by the template, we need to use the cocos run command in the format of cocos run-p [platform]. For example, cocos run-p win32 indicates the win32 platform.

When executing this command, note that the directory for executing the command must be the root directory of the game project. If it is not in the root directory, use-s to specify the location of the game root directory.


Now we execute cocos run-p win32-s e: \ simple in cmd. The result is as follows:


If there are no errors during compilation, the HelloWorld DEMO will be opened after compilation is complete.

Now, the Environment setup and debugging are all OK.


Part 4:

The Android compilation environment has also been greatly improved in 3.0RC, And the deployment and compilation methods are much more convenient than before.

Android compilation environment requires the use of Andorid_SDK Android_NDK Ant and JDK


In addition to JDK installation, others can be directly decompressed in the green version.

We decompress the sdk ndk and ANT to the same folder and modify the sdk folder name ADT (which can be left unchanged). The NDK of NDK and ANT are ANT for future use. After decompression, all files are stored in the e: \ Android folder.



After decompression, configure JDK first.

After JDK is installed, you must manually configure environment variables.


1) create a JAVA_HOME variable in the system variable. The variable value is C: \ ProgramFiles \ Java \ jdk1.6.0 _ 14 (set it according to your installation path)

2) create a new classpath variable with the variable value:.; % JAVA_HOME % \ lib \ tools. jar (note that the previous. Do not forget it)

3) Add the variable value % JAVA_HOME % \ bin; % JAVA_HOME % \ jre \ bin in the path variable (no need to create a new variable) (note that the variable values are separated)

4. log out of the system again and log on again to "start" --> "run" --> Enter "javac" --> "Enter". If you can print the command properly, the configuration is successful!

Analysis of supplemental environment variables:

JAVA_HOME: jdk installation path

Classpath: the class path loaded by java. Only the java commands of the class in classpath can be identified. A "." is added before the path to indicate the current path.

Path: The system can recognize java and javac commands in any path.


Now let's configure the ANT environment variable. Add the [ANT Directory] \ bin folder to path



Now the preparation is complete. Next we will run setup. py to associate the sdk ndk and ANT


Here we enter the ndk and sdk paths, where the ndk points to the root directory, and the sdk needs to point to the sdk directory in the adt.


After the two environment variables are added by setup. py, we are required to enter the Ant path. here we need to point to the bin folder in ant as follows:


At this time, the basic environment has been set up. Remember to log out and log on again to make the environment variable take effect.




Run setup. py again to check whether all the configurations are correct.



Then we can use cocos compile-p android to compile the APK file in the root directory of the created Project.


Note: before packaging the apk, you must modify the android. mk file in the proj. Android/jni folder to add the CPP file you have added.

Finally, let's take a look at the compiled APK file, which is located in the [project folder] \ bin \ debug \ android \ folder.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.