As a heavy-weight cross-platform development of the game engine, cocos2d-x in today's hand-tour development field occupies an important position. So the problem is, as a cocos2dx learner, it has the portability characteristics that we need to master, or we always feel less of a skill. However, this time all sorts of problems have come, before the online has been a piecemeal transplant tutorial, but are incomplete, or have such or such a problem. Today we have just researched the success of the cocos2dx-3.0 version of the Android platform transplant problem, I personally completed the entire process, the cocos2dx-3.0 version from the development environment (WIN32) to the project porting Android platform to share with the process.
First, the development environment to build
1. Tools
(1) Python 2.7.5
(2) cocos2d-x3.0
(3) vs2012
2. Steps
(1) Installing the Python environment
Once you have downloaded Python, install it by default. We also need to configure environment variables after installation.
Action: Right--My computer, properties, advanced system settings, Advanced tab, environment variables, system variables. Locate the path variable and add the Python environment variable (installation directory) at the end of its value.
(2) Configuration cocos2dx
After downloading, we unzip to the disk, and open the Cocos2d-x folder to find the setup.py file and run, the console will appear as follows:
Always press ENTER until you exit, and this Python script file will help us set the environment variables required for the cocos2d-x to run. This COCOS2DX environment is configured to complete.
(3) Create a project
Enter the directory cocos2d-x-3.0/tools/cocos2d-console/bin/cocos.py.
Open terminal Run cocos.py script to create project:
python cocos.py new HelloCpp -p com.coco2dx.org -l cpp -d ~/Desktop
Parameter description:
- Hellocpp for Project name
- -P Follow-up package name
- -L followed by development language type
- -D followed by Project storage directory
Looking at the project path, you will see that the new "Hellocpp" item appears in the directory. Open the Hellocpp/proj.win32 folder, then the HelloCpp.sln solution, and click Run Project. The following interface appears and the project was created successfully.
Second, the Android platform to transplant
1. Tools
(1) Android_sdk
(2) ANDROID_NDK (Note that this must be downloaded in the NDK r9d version only)
(3) Android_jdk
(4) Ant
2. Steps
(1) Installation tools
ANDROID_SDK, android_ndk and ant do not need to be installed, directly extracted to the local disk;
We unzip the SDK NDK and ant into the same folder and modify the SDK's folder named Adt,ndk ndk,ant as Ant, and then put it into D:\Android directory for easy use later.
ANDROID_SDK Choose the default installation method to install, then you need to manually configure the environment variables:
1) New system environment variable Java_home variable, variable value: C:\Program files\java\jdk1.8.0_91
2) New CLASSPATH variable, variable value is:.; %java_home%\lib;%java_home%\lib\tools.jar
3) Add the value of the variable at the end of the path variable:%java_home%\bin;%java_home%\jre\bin
4, Win+r run Javac command, if you can print usage instructions successfully configured
Then configure the ant environment variables. Add the [Ant directory]\bin folder to the path:
(2) Installation ANDROID_SDK
Open the SDK Manager.exe in the ADT directory and install the SDK tools for the version you need.
(3) Configuring the Environment
Now that you can associate the Android environment with the COCOS2DX, let's run the Setup.py affiliate SDK NDK and Ant:
1) Enter the root directory of the NDK and press ENTER;
2) Enter the root directory of ADT and press ENTER;
3) Enter the Bin folder directory in Ant and press ENTER;
The association is complete. Rerun setup.py confirm that all the configurations are correct. If all is correct
(4) Successful transplant
Then, under Project Root shift+, right-click to run the command line and enter:
Cocos Compile-p android-21
-
- -21 is the SDK tools version I installed;
- Before packaging the APK, you need to modify the Android.mk file under the Proj.android/jni folder to add all CPP files
This will compile the apk file, located in the [Project folder]\bin\debug\android\ folder, can be installed to the mobile phone or Android simulator run.
cocos2dx-3.0 version from development environment Building (WIN32) to project porting Android platform process