Cocos2dx environment configuration and packaging
Installation Software preparation: vs2012cocos2d-x-2.2.1adt-bundle-windows-x86_64-20121030android-ndk-r9c-windows-x86_64jdk-7u21-windows-x64python-2.7.6.amd64cygwin64 setup-x86_64
Step 1: Install visual studio 2012It is used to develop the cocos2dx program. You can find the cocos2dx program by yourself.
Step 2: Download The cocos2d-x source code: Http://www.cocos2d-x.org/download/version#Cocos2d-x
Add the environment variable COCOS2DX_ROOT = to the user variable. Cocos2d-x-2.2.1
Step 3: Install pythonThe python command is used when you create a cocos2d program, with a script under the cocos2d-x-2.2.1/tools/project-creator/: create_project.py: Program
Add the following content to the system variable path: C: \ Python27;
Step 3: Install the java sdkThe SDK is short for Software Development Kit"
JDK is the abbreviation of Java Development Kit"
So, it is not difficult to see that the SDK is a general term, JDK is a specific software development kit in the SDK: http://www.oracle.com/technetwork/java/javase/downloads/
Step 4: Install the latest Android ADT bundle and Android NDK
Android ADT bundle
ADT: Android Development Tools, plug-ins in ecplise, Android Development tool plug-ins
Android ADT bundle contains the adt and its compatible ecplise software.
Android sdk can be understood as an android development tool. In fact, it is used as a plug-in of eclipse. With it, you can develop android programs in eclipse.
Android NDK
NDK is a collection of tools. NDK provides a series of tools to help developers quickly develop C (or C ++) dynamic libraries, and can automatically set. so and java application 1
And then package it into an apk. These tools are of great help to developers. NDK integrates with the cross compiler and provides the mk file isolation platform, CPU, and API.
Differences: developers can create a. so file by simply modifying the mk file (indicating "which files need to be compiled" and "Compilation feature requirements. NDK can be self-built
Dynamically package. so and Java applications, greatly reducing developers' packaging work. NDK provides a stable and functional API header file statement. Googl
E explicitly states that this API is stable and supports the currently released API in all subsequent versions. From the NDK of this version, we can see that these Apis support many functions.
Limits, including: C standard library (libc), standard library (libm), compression library (libz), and Log Library (liblog)
Download the latest ADT Bundle for Windows from http://developer.android.com/sdk/
Decompress the adt-bundle-windows-x86_64-20121030.zip to change the directory adt-bundle-windows-x86_64-20121030 to android directory android \ sdk to android \ android-sdk-windows
Download Android NDK r9c from http://developer.android.com/tools/sdk/ndk/index.html
Extract android-ndk-r9c-windows-x86.zip move directory android-ndk-r9c to android \ android-ndk-r9c
The final directory structure:
\ Android-ndk-r?
\ Android-sdk-windows
\ Android \ eclipse \ Android \ SDK Manager.exe
Run android \ android-sdk-windows \ tools \ android. bat, select Android SDK 2.2 (if you cannot see Android SDK 2.2, set a proxy), and install the required package
Add the environment variable ANDROID_NDK_ROOT = to the user variable. Android-ndk-r9c
ANDROID_SDK_ROOT = \ Android-sdk-windows
ANDROID_HOME = % ANDROID_SDK_ROOT %
Step 5: Install cygwin <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Release + release/KOsxOO + zb/J0tTU2rK7sLLXsGxpbnV4tcS + sM/release + sLrwcsKPGJyPgoKsLLXsM/qveKjugrE47XDz8jF3LW9 Release/rk9o7rrodt1_lxsle9yr2jrlxa0ru0zr/release/fz8LU2LCy17CjrMjn09DP1rPJtcTA68/fsPyjrL/release = "http://www.2cto.com/uploadfile/2014/0806/20140806111049340.png" alt = "\"> Step 3: select the installation directory, for example, C: \ Cygwin. Note that this directory is the final installation directory of Cygwin, rather than the temporary directory for downloading files. Step 4: set the path for saving local packages
The current directory is stored in the directory of the same level as setup.exe. The downloaded directory is named ftp % 3a % 2f % 2fcygwin.mirrors.pair.com % 2f. Step 5: Set the network connection mode. Step 6: select the download site address.
At first, I tried to check which address is used for the fast speed (if it doesn't feel fast, I 'd like to cancel it and try again ). Http://mirrors.kernel.org, speed feeling infection is still quite fast Step 7: Wait for loading the installation item load, select the installation item
We compile NDK. Under the Default settings, we only need to select Devel (Click Devel in the list and change Default to Install, as shown by the arrow in the figure). The other options are Default.
Step 8: wait until the download is complete
The download completion time is determined by the number of installation packages you selected and the network connection speed. For example, according to the default method in this article, it may take 4-5 hours. After downloading, the compressed package is about 950 MB, after the download is complete, it will be automatically installed to the installation directory set above
Reminder: after the first download is complete, you 'd better back up the downloaded package directory. You can directly use the offline Installation Method for the next installation of the same environment (select local installation in step 2 ).
Step 9: Verify the Cygwin Environment
After the installation is complete, run Cygwin once (Cygwin. bat) to create some user environment files and enter:
Make-v
And,
Gcc-v
If the check succeeds, make and gcc versions are printed.
Next, modify the file in the cygwin installation directory. For example, the installation directory is D: \ cygwin64 \ home \ yangxg.
Then it is best to open. bash_profile In the UE editor, and add the ndk path and cocos2dx path at the bottom.
NDK_ROOT =/cygdrive/e/android/android-ndk-r9c.
Export NDK_ROOT
COCOS2DX_ROOT =/cygdrive/e/cocos2d-x-2.2.1
Export COCOS2DX_ROOT
Restart cygwin and enter:
Cd $ NDK_ROOT
You can enter the corresponding directory of the ndk and set OK.
Add the following content to the system variable path: D: \ cygwin64 \ bin;
Step 6: Compile cocos2dx:Go to the cocos2dx directory and run the cocos2d-win32.vc2012.sln to compile HelloCpp
Compiled successfully
========================================================== ================================== ========================================================== ==================================Next we will teach you to create a cocos2dx project to enter the directory cocos2d-x-2.2.1/tools/project-creator/-- there is a script: create_project.py using this script will help us create a cocos2dx program, to execute this script, you need to install python. In the above tutorial, we installed python to create the project eg: python create_project.py-project gametest04-package cn. yangxg. gametest04-language cpp create a cocos2dx program named: gametest04, package name: cn. yangxg. gametest04, language: cpp this program is created under the Directory: cocos2d-x-2.2.1/projects/gametest04
Open gametest04/proj. win32 and run gametest04.sln compilation. It takes some time for the first compilation.
========================================================== ================================== ========================================================== ==================================After learning to create a cocos2dx project, we will begin to learn how to package the project into apk1. in win32. h and. copy the cpp file to Classes (if you want to modify those later. cpp file or. the H file needs to continue from proj. win32 copies to Classes and overwrites the previous files to generate a new android project.) 2) Enter proj. android: Use the UE editor to modify the build_native.sh file.
Add the following content under the third line:
NDK_ROOT =/cygdrive/e/android/android-ndk-r9c.
COCOS2DX_ROOT =/cygdrive/e/cocos2d-x-2.2.1
GAME_ROOT = $ COCOS2DX_ROOT/projects/gametest04
GAME_ANDROID_ROOT = $ GAME_ROOT/proj. android
RESOURCE_ROOT = $ GAME_ROOT/Resources3) Go to proj. android \ jni and modify Android. mk,
Add all. cpp paths. If I have added the following paths, after modifying these paths, make sure they are correct.
Open cygwin and enter the directory gametest04/proj. android/execution. /build_native.sh to the end. no error after/build_native.sh (this process takes about 10 to 20 minutes, and some may take half an hour ), it will produce the android project (the successful judgment is to check whether it is produced. so file)
If it succeeds, you can see the libcocos2dcpp. so file in the path cocos2d-x-2.2.1 \ projects \ gametest04 \ proj. android \ libs \ armeabi.
Then you can generate the android project that can run on eclipse, import cocos2d-x-2.2.1 \ projects \ gametest04 \ proj. android this can be seen on eclipse the project
After the project is loaded in will prompt the lack of cocos2dx package, we go to the cocos2d-x-2.2.1/cocos2dx/pathform/android/java/scr/copy the org file to our project gametest04/proj. android/src/
Next, refresh our project. If it's okay, you can compile it.
After successful running, an apk file will be generated in bin/. If you need to make the project portrait on the real machine, you only need to create a portrait in AndroidManifest. in xml, the android: screenOrientation = "landscape" (landscape), android: screenOrientation = "portrait" (landscape), which defaults to landscape
All right, the apk package is complete.