(Transferred from: http://www.cnblogs.com/Richard-Core/p/3855130.html)
From COCOS2DX 3.2 Project to apk Android app file, the steps to build an Android environment are a bit cumbersome, but once built, it will be very fast!
(related to 3.1.1 version, please automatically correspond to the 3.2 version, the 3.x version of the environment is the same)
First, download the Android environment
Android SDK, NDK, Ant, and JDK are needed to build the Android environment.
Android SDK Download http://developer.android.com/sdk/index.html
Android ndk Download http://developer.android.com/tools/sdk/ndk/index.html
Android JDK Download http://www.oracle.com/technetwork/java/javase/downloads/index.html
Ant Download http://ant.apache.org/bindownload.cgi
Where the JDK needs to be installed, the others are directly extracted. Unzip the SDK NDK and ant into the same folder, and the files are all in the E:\Android folder after I unzip them.
SDK if downloaded the ADT file then the inside of the SDK folder to test out, modified
Second, configure the JDK
After the JDK has been installed, you need to manually configure the environment variables
1, the system variable in the new Java_home variable, the value of the variable is: C:\Program files\java\jdk1.8.0_05 (according to their own installation path fill)
2, the new system variable CLASSPATH variable, the value of the variable is:
.; %java_home%\lib;%java_home%\lib\tools.jar (Note the previous.) Don't forget it)
3. Add variable values in the system variable path variable (existing without new):
%java_home%\bin;%java_home%\jre\bin (Note the value of the variable with ";" Separated
Analysis of environment variables:
Installation path for JAVA_HOME:JDK
Classpath:java load Classpath, only the class is recognized by the Java command in Classpath, and a "." is added before the path. Represents the current path.
Path: The Java,javac command can be recognized by the system under any path.
After the configuration is complete, we open the cmd command window, enter Java or javac carriage return, if not print "Java is not internal or external command" That means the configuration is successful.
Third, configure the ant environment variable
Add ant's Storage path to the system path variable.
Iv. Configuring COCOS2DX 3.1 Android Environment Association
The above is ready to open the COCOS2DX directory of setup.py.
Enter the path to the NDK.
Enter the SDK path
The last input is the ant path.
OK, three paths are already configured
Five, packaging apk
You can then compile the apk file in the project directory using Cocos compile-p Android.
Note: Before packaging the APK, you need to modify the Android.mk file in the Proj.android/jni folder to add your own new CPP file, where the new is the non-COCOS2DX generated project file (your own new file). Be sure to include your new files or folders in the APK.
First of all, we take the official Cpp-tests project to hackers it!
Hold down the SHIFT key + right mouse button to select the Command window to open here.
You can then compile the apk file using the Cocos compile-p Android--ap 20 Way (--ap 20 is the specified Android platform)
Long wait, of course, here to remind a Point 3.1 version is android-20, if the E:\Android\sdk\platforms directory is not android-20 please create an empty.
After waiting, look at the APK in this folder! Can be installed on the phone to try it.
Six, exception handling: (I will be the update encountered problems, so that people do not take the road)
1. Android platform not specified, searching a default one ...
Can ' t find right android-platform for project:
"F:\cocos2d-x-3.1.1\tests\cpp-tests\proj.android".
The android-platform should be equal/larger than 20
If you encounter this problem, then you need to
Under Create an empty android-20 folder, this problem pits me for a long time! Also check to see if the command is –ap 20 (double-).
Check if the project.properties in the \proj.android directory is android-20
2. At compile time, you are prompted not to find the GCC toolchain (couldn ' t find the GCC toolchain).
This problem has been bothering me for a long time! Go check the NDK configuration path! Ndk_root is correct! Then the 3.1 version required the NDK to be the latest version,
Go to the Android website http://developer.android.com/tools/sdk/ndk/index.html#Installing next latest version r9d!
3. If you encounter problems with Android API
Find the run to update, see which API is missing which update, but this update is slow ... The reason Google is banned ...
4, Android ndk:invalid App_stl value:c++_static this to modify Jni/application.mk
App_stl: = c++_static
Ndk_toolchain_version=clang
App_cppflags: =-frtti-dcc_enable_chipmunk_integration=1-std=c++11-fsigned-char
App_ldflags: =-latomic
Change to:
App_stl: = gnustl_static
# add-wno-literal-suffix to avoid warning:warning:invalid suffix on literal; C++11 requires a space between literal and identifier [-wliteral-suffix]
# in Ndk_root/arch-arm/usr/include/sys/cdefs_elf.h:35:28:when using NDK-R9
App_cppflags: =-frtti-dcocos2d_debug=1-std=c++11-wno-literal-suffix-fsigned-char
5, Android NDK:WARNING:APP_PLATFORM android-14 is larger than Android:minsdkversion 8
This is because the NDK specifies a version that is inconsistent with minsdkversion and modifies the Androidmanifest.xml file where Android:minsdkversion is modified to <USES-SDK android: Minsdkversion= "/>"
-----------------------------------------------------------------
I also encountered another problem, is to install the APK file with the phone is displayed horizontally, if you want to display the vertical screen, you need to set the "Android:screenorientation" in the Androidmanifest.xml to portrait.
Cocos2d-x 3.2 Pack Android platform apk