Build cocos2d-x3.2 environment and configure Android cross-compilation environment under Windows environment

Source: Internet
Author: User

First, the software

1) VS2012 (c++11 characteristics can be used above the VS2012); Portal:

2) Cocos2d-x official website source; Portal: http://cocos2d-x.org/download

3) JDK; Portal: https://github.com/inferjay/AndroidDevTools/

4) NDK; Portal: https://github.com/inferjay/AndroidDevTools/

5) ANT; Portal: https://github.com/inferjay/AndroidDevTools/

6) Python; Portal: https://github.com/inferjay/AndroidDevTools/

Second, software Installation and environment configuration

1. VS Environment Installation

2, JDK Environment installation: Right-click Computer, Properties----Advanced system settings, environment variables (divided into user variables and system variables);

1) Installation: Click on the next step to complete the installation.

2) Configure the environment variable: a) in the system or user variable java_home the new environment variable to the JDK path, such as: D:\java,java for the JDK installation folder; b) Add "%java_home%\bin" to the path of the system variable, remember to separate it with semicolons. Add the classpath variable to the user variable as ".; %java_home%\lib; " Notice there's a point ahead. The JDK environment configuration is complete.

3) Start and run->cmd or win+r into the DOS window: Enter java-version to see if the JDK was installed successfully. Restart the DOS window and the environment is configured successfully.

3, Ant Environment installation:

1) Decompression apache-ant-1.9.3-bin.zip,ant is a batch processing tool;

2) Set Ant_root, such as: D:\cocos\apache-ant-1.9.3\bin,bin is the bin folder in my ant installation directory, Ant_root environment variables are added to system users

3) Add "%ant_root%" to the system variable path and remember to separate the semicolon.

4. ADT Environment installation (including SDK and Eclipse)

1) decompression adt-bundle-windows-x86-20140624.zip;

2) Set the Android_sdk_root environment and increase the system variables. Values such as: "D:\COCOS\ADT-BUNDLE-WINDOWS-X86-20140624\SDK";

3) Add "%android_sdk_root%\tools" and "Android_sdk_root%\platform-tools" to the system path variable, remember to separate the semicolon.

4) After installing ADT, add the Eclipse.exe from the Eclipse directory to the desktop and double-click to complete the installation of the Eclipse ADT Environment.

5) into DOS, enter: Adb-h to see if the configuration is successful, turn off the DOS reboot to configure the success.

5, installation ndk:cocos2d-x3.2 to the NDK requirements r9d

1) decompression android-ndk-r9d-windows-x86.zip;

2) Set the NDK_ROOT environment variable and increase it in the system variable. Values such as: "D:\cocos\android-ndk-r9d";

3) Add "%ndk_root%" to the system variable path and remember to separate the semicolon.

6. Install Python: Next

1) Download and install the Python-2.7.5.msi (must be version 2.7)

2) Add the Python environment to the system path variable, such as: "C:\Python27";

The final path is as follows: "c:\python27;%java_home%\bin;%android_sdk_root%\tools;%android_sdk_root%\platform-tools;%ant_root%;% ndk_root%; "

Environment variables can be updated by restarting or shutting down DOS or computers after a successful configuration.

Enter the cocos2d-x3.2 root directory, execute setup.py under DOS to see if the above path exists and properly configured, if successful such as: and automatically generate COCOS_CONSOLE_ROOT environment variables under the user environment variable.

Iii. creating a new project for cocos2d-x3.2

1, enter the Cocos2d-x-3.2\tools\cocos2d-console\bin; under DOS enter: "cd/d file path" can be entered in any file path. You can also use the shift+ right click under the file you want to enter, and choose to open the Command window here, as well as enter the directory.

2, in the Terminal Input command: Cocos new project name-P package name-L cpp-d project Path, the project was created successfully;

3. Enter the project project under the Cocos\mycppgame\proj.win32 folder, double-click the. sln or. vcxproj to open the Project project, F5 run the program;

Iv. Compilation of Android environment

1. Open the DOS command window and enter the new project directory.

2, the implementation of Cocos Compile-p Android-j 4, will error, said to find platform,platform at least more than 10, the solution is: in cocos\adt-bundle-windows-x86-20140624\ The SDK adds android-20, empty folders can be. Because the 3.2 platform uses the ANDROID-20 platform, as long as it is an empty folder.

3, so discard the above 1 compile command, use Cocos compile-p Android-ap 20;

4, the generated apk in the project directory \bin\debug\android, directly copied to the phone, installation can be.

or execute the following command: (I have not tested the command, the Internet see)

1, run the project directory proj.android-> build_native.py build complete Android project

two ways to make no difference, just the first to generate the APK file directly, the second more convenient

will generate Android project must file, proj.android->libs->armeabi-> Libcocos2dcpp.so

V. Running in Eclipse: (reproduced here) reprinted from: http://blog.csdn.net/ku726999/article/details/38121927

Android development should already be well-equipped with the SDK

1. Import cocos2d-x jar Package

Eclipse menu File,Import,android--Existing android Code into Workspace

2, Import the project, the same

3, the project will be error, because there is no reference to the library file Cocos2d-x

Solution: Right-click the project selection Properties->android pull to the bottom

Remove Drop the error library file path,

ADD Select Libcocos2dx


4. in VS if new CPP file is created, the corresponding file needs to be added in Android.mk, the format is consistent with the diagram, note the relative path

5, Note that if you change the code in vs2012, you need to rerun the build_native.py


Reference Tutorials

Tutorial 1:http://www.mysjtu.com/page/m0/s962/962815.html
Tutorial 2:http://blog.csdn.net/myarrow/article/details/24474933
Tutorial 3:HTTP://WWW.TUICOOL.COM/ARTICLES/YRAZFV
Tutorial 4:http://blog.csdn.net/ku726999/article/details/38121927

Share resources: Resources: https://github.com/inferjay/AndroidDevTools/


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: info-contact@alibabacloud.com 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.