Photo Link http://blog.csdn.net/wonengxing/article/details/23601359
~ ~ ~ My life, my little drops!!
One. Android Tool installation
1. Installing the JDK
jdk:http://www.oracle.com/technetwork/java/javase/downloads/index.html Because this is the official website, assuming not to go or download slow,
Can self-Baidu or Google download, I am anyway to download the latest, tube him
Assuming you have a large C drive, then install it by default, I am not enough for the C drive, so I installed the D plate D:\Program files\java\jdk1.8.0
environment variable Settings
Java_home=c:\program Files (x86) \java\jdk1.7.0_21classpath=.; %java_home%\lib;path add %java_home%\bin; If you know how to set the environment variable, if you do not know, please use search engine to find relevant information, set up cmd, enter java-versionassume that the following prompt indicates the success of setting the environment variable:
2. Download the android SDK
Google provides an ADT (Android Developer Tools) for Android developers, including the SDK and Eclipse.
Yes: http://developer.android.com/sdk/index.html
unzip it to a folder, I am here: d:\adt-bundle-windows-x86\, folder structure such as the following:
--<adt-bundle-windows-x86>
--<eclipse>
--<sdk>
--SDK Manager.exe
environment variable Settings
Then add in path such as the following code%android_sdk_root%\tools;%android_sdk_root%\platform-tools;
One is the path of the ADB, one is the path of the emulator simulator, note the semicolon separated
3. Download Android NDK
Yes: http://developer.android.com/tools/sdk/ndk/index.html
The same 32-bit and 64-bit version is optional, I chose the 32-bit version, unzip it into the ADT folder, now ADT folder structure such as the following:
--<adt-bundle-windows-x86>
--<eclipse>
--<sdk>
--<android-ndk-r8e>
--SDK Manager.exe
environment variable Settings
Add%ndk_root% to Path;
4. Download the Ant
Ant is used to build Android programs on its own initiative.
Yes: http://ant.apache.org/bindownload.cgi
I chose: apache-ant-1.9.4-bin.zip, the same decompression to the ADT folder, now ADT folder structure such as the following:
--<adt-bundle-windows-x86>
--<eclipse>
--<sdk>
--<android-ndk-r9d>
--<apache-ant-1.9.4>
--SDK Manager.exe
See Clearly, my ANT is directly set to the Bin folder, so in path still only need to join%ant_root%;
5. Download Python
Originally cocos2dx in different platforms must be created and built with different scripts project,3.0 after the unified use of Python, so windows need to install the Python environment:
: Https://www.python.org/ftp/python/2.7.3/python-2.7.3.msi
Originally downloaded the latest version number, when using setup.py found a syntax error, so it is best to use the 2.7.3 version number, tested no problem
Configure environment variables: The latest version number can be actively added to the PATH environment variable, but 2.7.3 not, so we can only set it ourselves, if my Python installed in: d:\Python27\
Add this path to the PATH environment variable, and when we enter Python under CMD, the following word appears, stating that the environment variable is set correctly:
C:\users\arlin>python
Python 2.7.3 (default, APR, 23:31:26) [MSC v.1500 + bit (Intel)] on Win32
Type "Help", "copyright", "credits" or "license" for more information.
>>>
two. cocos2d-x Download and Configuration
1. Download Cocos2d-x
Now the latest version number is 3.0, yes: Http://www.cocos2d-x.org/download/version#Cocos2d-x
Download the unzip to a place I am here: E:\cocos2dx3.0\cocos2d-x-3.0\cocos2d-x-3.0
2. Environment variable Settings
CC requires the following environment variables for creating new project, building project, and so on later:
Cocos_console_root:cocos console path, console for new, build, release project.
Add%cocos_console_root% to Path;
In the environment variable user area, add the following several
NDK_ROOT:NDK root Folder
ANDROID_SDK_ROOT:SDK root Folder
Ant_root:ant root Folder
Then execute the cocos2d-x root folder under the setup.py to configure, assuming that the previous items have been filled out correctly, the following will be once,
Assuming that it is not filled in, the following will give you a hint to fill in these items, and then enter OK, assuming that the following lines appear to be successful
Restart the terminal or restart computer to make added system variables t
Ake effect
The command finally prompts us to restart the terminal or reboot the system for these environment variables to take effect, usually we close cmd and resource Explorer, assuming that the environment variable is not found in the following error,
Just reboot the system and try it out.
To test whether the environment variable is in effect, once again open cmd, enter the following command to view, normal should be this:
E:\cocos2dx3.0\cocos2d-x-3.0\cocos2d-x-3.0>set Ndk_root
ndk_root=d:\adt-bundle-windows-x86\android-ndk-r9d
E:\cocos2dx3.0\cocos2d-x-3.0\cocos2d-x-3.0>set Ant_root
Ant_root=d:\adt-bundle-windows-x86\apache-ant-1.9.4\bin
E:\cocos2dx3.0\cocos2d-x-3.0\cocos2d-x-3.0>set Android_sdk_root
Android_sdk_root=d:\adt-bundle-windows-x86\sdk
E:\cocos2dx3.0\cocos2d-x-3.0\cocos2d-x-3.0>set Cocos_console_root
Cocos_console_root=f:\cocos2dx\cocos2d-x-3.0rc0\tools/cocos2d-console/bin
OK, here, the environment is ready to go down to create a project!
3. Create and Build Project
1. Create a new project
To create a new project with Tools\cocos2d-console, this tool provides several features:
Create a new project
Compile compiles the current project, generates binaries, and personally thinks it's more appropriate to write as build.
Deploy announcement program to a platform
Run compile and advertise, and execute the program
Now we're just using new, let's see what the new parameters are, hit cmd, enter:
Cocos New--help
See for yourself here, I'll give you a direct way to create project
Cocos new own project name-p package name-L CPP (for creating C + +)-D E:\cocosProject (path to project storage)
Here is a bat file, just double-click it.
@echo Offecho =========== New Project =========set/p name= Enter the name of the project: The Echo project is named:%name%echo is creating a new project ... set pk=com.hzf.cocos new% Name%-P%pk%%name%-L cpp-d E:\cocosProjectecho creation Complete Pause
TP: Assuming that the direct copy executes the times wrong, can be manually knocked over.
Can see the various platforms under the project has been created, the same time it cocos2d the entire framework is copied over, so good or bad, but can be certain,
That is the first time the compilation will be very slow, because you want to compile all over again, so it's okay to never build again!! Cut (the lesson of the blood)
2. Build Androidproject
The same time is used to cocos2d-console, here is to use compile this command, in CMD input the following to see the help:
E:\cocosproject\mbgame\mygame1>cocos Compile--help
Usage:cocos compile [-h] [-s src_dir] [-Q] [-P PLATFORM] [-M MODE] [-j JOBS]
[--ap Android_platform] [--source-map]
Compiling the current project into a binary
Optional number of references:
-H,--help display Help information
-S Src_dir,--src Src_dir
Project root folder, for example, above should be E:\cocosProject\mbgame\mygame1
If not set, it is the current folder (the one that CMD navigates to)
-Q,--quiet less output
-P PLATFORM,--platform PLATFORM
Select a platform Android|ios|mac|web|win32|linux
-m mode,--mode mode debug|release, defaults to debug.
-j jobs,--jobs jobs Half-line compilation, assuming you have 2 cores, can be set to 2.
Android Options:
--ap Android_platform
Specify the SDK version number? Have not tried, dare not to the conclusion, keep English:
Parameter for Android-update. Without the Parameter,the
Script just build dynamic library for project. Valid
Android-platform Are:[10|11|12|13|14|15|16|17|18|19]
Web Options:
--source-map Enable Source-map
Now we are typing in cmd:
E:\cocosproject\mbgame\mygame1>cocos compile-p android-j 2
It means that we want to compile the current folder under the Androidproject, the same time can have 4 compile tasks, so my 4-core machine is full of negative run, such as no accident, should be able to see the start of the compilation, and finally assume that the following statements, the compilation is successful:
BUILD Successful
Total time:17 seconds
Move apk to E:\cocosProject\mbgame\mygame1\bin\debug\android
Build succeeded.
We went to E:\cocosProject\mbgame\mygame1\proj.android\bin\ and was able to see the mygame1-debug.apk, and the construction was complete.
I installed it on the phone to try to run, found that it seems to start the speed is very much faster, do not know whether it is psychological effect.
Three. Executing the program under Eclipse
Do you remember that we have eclipse in ADT and now we're going to import project into Eclipse and run to see
1. Hit the d:\adt-bundle-windows-x86\eclipse to Eclipse.exe
The first time you'll be prompted to set up a workspace, you can set where the workspace is placed, and I'll default for the demo here.
2. Next we'll look at whether the SDK and NDK paths are correct:
Select the Windwos/preferences menu item to open the Options dialog box.
Select the Android node to see if the SDK location is correct, I am F:\software\adt-bundle-windows-x86-20131030\sdk here, it is correct, assuming that there is no value, manually set the root folder of the SDK.
Then select the ANDROID/NDK node and enter the d:\adt-bundle-windows-x86\android-ndk-r8e at the NDK location
3. Next we'll import project, select File/import, and open the Import dialog box:
Choose Android/existing Android Code into Workspace, and then next.
The first step is to LIBCOCOS2DX in:
Enter F:\cocos2dx\mbgame\mygame1\cocos2d\cocos\2d\platform\android\java in root directory
List Libcocos2dxproject at this point and click Finish to bring project in.
The second step is to import our project:
Enter F:\cocos2dx\mbgame\mygame1\proj.android in root directory.
Mygame1project is listed at this point, click Finish to bring project in.
Finally connect the phone, choose to perform or debug can run the program.
When you import project to eclipse, you encounter several pits, which are written down here, lest the people behind continue to tread on these pits:
There is no guide libcocos2dx, only the mygame1 will not compile errors, but run up will classnotfound abnormal, said can not find Org/cocos2dx/lib/cocos2dxhelper class, this problem engaged me for a long time, Later in the forum to see the post is clear, I hope perhaps the official documents.
Since ADT only includes the version number of the android4.4 (api-19), the default is to use this version number, I have to copy a few of the lower version number, and then set the build target to android2.3 (api-9), when the execution program will prompt the following error:
Unable to execute dex:java.nio.BufferOverflowException
Later on the Internet, found that is the Android SDK build tools bug, upgrade it to 19.0.3: Open the SDK Manager, find the 19.0.3 Android SDK build tools, installation.
cocos2dx-3.0 (1)------Win7 32-bit Android environment