1, the Android environment collocation:
- Download JDK
- Download Android ADT
- Download install Android SDK, address: http://developer.android.com/sdk/index.html#download
- Create AVD
2. Download Android NDK: Http://developer.android.com/tools/sdk/ndk/index.html#download the NDK is a collection of a range of tools. The NDK provides a range of tools to help developers quickly develop C (or C + +) dynamic libraries and automatically package so and Java applications together as APK.
3, installation Cygwin:Because the NDK compiles the code with make and GCC, so you have to build a Linux scene, Cygwin is a UNIX parody that runs on the Windows platform, and it's about learning unix/linux manipulation, or porting from UNIX to Windows, it's a valid application. With it, you can use the NDK to compile C, C + + code without installing Linux.
Installation Detailed:
You'll have to run to http://www.cygwin.com. Download setup.exe
The first step: Run the Setup program, the first step of the diagram, click Next directly to enter the next step.
The second step: Choose the installation method, the first time can be used direct connection online download installation, if there is an off-the-shelf offline package, you can choose to install offline (install from Local Directory).
The third step: Select the installation directory, such as C:\Cygwin, note that this directory refers to the Cygwin final installation directory, not the download file staging directory.
Fourth Step: Set the local package staging pathThe staging directory is placed in the Setup.exe sibling directory by default, and the downloaded name is similar to the FTP%3A%2F%2FCYGWIN.MIRRORS.PAIR.COM%2F format
Fifth step: Set up network connection mode
Sixth step: Select Download Site Address
At first try a few to see which speed to use which address (if you feel uncomfortable, click Cancel, again). Http://mirrors.kernel.org, the speed feels pretty fast.
Seventh Step: Wait for the loading of the installation item to load, select the installation item
we compile the NDK, in the default settings, just select Devel (click on devel in the list, change the following default to install, the arrow in the figure), and the others are the defaults.
Eighth step: Wait for the download to complete
The download completion time depends on the number of packages you choose and the network connection speed, for example, according to the default selection method of this article, it may take 4-5 hours, download the package is about 950M, after the download is completed automatically installed to the installation directory set above
Reminder: After the first download is completed, it is best to make a backup of the downloaded package directory, the next time you install the same environment can directly use the offline installation method (in the second step, select Local installation).
Nineth Step: Verifying the Cygwin environment
Once the installation is complete, run Cygwin once (Cygwin.bat) to create some user environment files and enter them separately:
Make-v
And
Gcc-v
If the test is successful, the make and GCC related version information is printed. Such as:
Next is the modification in the installation Cygwin directory, such as I install the directory below C:\cygwin64, and then use the editor point Open. Bash_profile (under the home folder: C:\cygwin64\home\john Chen), then add the NDK path and the COCOS2DX path at the bottom:
#创建NDK的路径,在windows中我的路径为:E:/Cocos2D/android/android-ndk-r9c
NDK_ROOT=/cygdrive/e/Cocos2D/android/android-ndk-r9c
#添加到PATH环境变量中
export NDK_ROOT
#创建cocos2d-x的路径,在windows中我的路径为:E:/Cocos2D/cocos2d-x-2.2.2
COCOS2DX_ROOT=/cygdrive/e/Cocos2D/cocos2d-x-2.2.2
#添加到PATH环境变量中
export COCOS2DX_ROOT
Restart Cygwin, enter: $ cd $NDK _root, you can enter the NDK corresponding directory on the instructions set OK, such as:
Add content after the system variable path: D:\cygwin64\bin;
4. Create Cocos2d-x Project:
To create the HelloWorld project as an example, execute the create_project.py script and enter the following command into the doc interface:
(1) E: (switch letter, because my cocos2d-x source in the e-disk, create_project.py in the directory. )
(2) CD E:\Cocos2D\cocos2d-x-2.2.2\tools\project-creator (Enter the directory where the create_project.py script is located)
(3) Download python,:http://www.python.org/getit/releases/2.7/.
(4) Run the cmd command to generate the HelloWorld project in Python with the following command:
Python create_project.py-project helloworld-package com.cocos2dx.org-language cpp (where HelloWorld is the project name, Com.cocos2dx.org for my Android version of the package identification name, remember that the package name does not appear special symbols such as "-", or import into eclipse will be an error. )
As you can see, running the Pyhton script generates projects for various platforms, such as iOS, Android, Win32, Mac, Linux, and more.
After running, the newly created HelloWorld project is located in the corresponding E:\Cocos2D\cocos2d-x-2.2.2\projects directory, with the following directory structure:
5, compiling cocos2d-x project:1) Copy the. h and. cpp files from the Proj.win32 into the classes (if you later modify those. cpp files or. h files, you need to continue to regenerate the files from the Proj.win32 copy to the classes to the new Android project)
2) Enter Proj.android, modify the build_native.sh file with the editor to add below the # options below:
NDK_ROOT=/cygdrive/e/Cocos2D/android/android-ndk-r9c
COCOS2DX_ROOT=/cygdrive/e/Cocos2D/cocos2d-x-2.2.2
GAME_ROOT=$COCOS2DX_ROOT/projects/HelloWorld
GAME_ANDROID_ROOT=$GAME_ROOT/proj.android
RESOURCE_ROOT=$GAME_ROOT/Resources
3) go in Proj.android\jni and modify the android.mk below.
Add all the paths to the. cpp, as I added the following paths
4) compile with Cygwin, after modifying these guarantees without error,Open Cygwin:A. Enter the downloaded Cocox2d-x directory to execute the following code:
$ cd $COCOS2DX_ROOT
$ chmod -R 755 *
Description: The above actions are intended to eliminate potential problems caused by permissions early, and you may experience permissions issues if you do not do so later. After this step is executed, subsequent recompilation can be skipped, or subsequent permissions problems can be performed again.
b, a operation completed after the entry into the project Android version of the directory projects/helloworld/proj.android execution./build_native.sh to the end./build_ Native.sh does not make mistakes after execution, it will produce the Android project (the success is judged to see if he produces. so files), the path is as follows:
5) Android project running on Eclipse, import projects/helloworld/proj.android This will see the project on Eclipse.
The project will be loaded into the missing COCOS2DX package, we go to cocos2d-x-2.2.2/cocos2dx/pathform/android/java/scr/to copy the org file to our projectHelloWorld/proj.android/src/under, refresh our project, OK no problem, you can compile the successful run will be generated in bin/an APK file if you need to make the project on the real machine into a vertical screen, just change in the Androidmanifest.xml, android:screenorientation= "Landscape" (horizontal screen), android:screenorientation= "Portrait" (vertical screen), it is the default horizontal screen.
Reference: http://blog.csdn.net/yeungxuguang/article/details/18217029
From for notes (Wiz)