This article is reproduced in http://www.cnblogs.com/zisou/p/cocos2d-xpeizhi0.html
The environmental requirements I am currently configuring are as follows:
JDK 1.6
XCode Version 4.6 (4h127)
Cocos2d-x 2.2.0
Android Developer
One, download the installation
To configure the environment one-time download prepare for the following things:
1, download JDK, address: http://www.oracle.com/technetwork/java/javase/downloads/index.html
2, download NDK, address: http://developer.android.com/tools/sdk/ndk/index.html
3, ADT + SDK, address: http://developer.android.com/sdk/index.html
4, download the latest COCOS2DX, has now reached the 2.2 version, address: Http://cocos2d-x.org/download official website changes quite large;
ps:2.1.5 more than the version of the build project to create some gaps;
5, download Xcode, my is the old version 4.6 do not upgrade, crack no certificate, there is no need to directly update the old version, you can go directly to the online download installation package;
PS: Crack address also give a bar http://blog.csdn.net/abcddtt/article/details/9074099 for no certificate or real machine debugging new projects to others to see very useful;
Second, the Environment configuration installation
1,ios Environment cocos2d-x2.2.0 version installation and upgrade
First install Xcode, and then extract the cocos2d-x2.2 files, from 2.1.5 or more after the installation of the template, directly after decompression with/users/yangshengjie/cocos2dx.2.2/cocos2d-x-2.2/tools/ Installation and construction of create_project.py files under the Project-creator directory
But if you want to upgrade the cocos2dx2.2.0 version before 2.1.5, do the following:
(1) Find the previous version of the install-templates-xcode.sh, such as cocos2d-x-2.1.4 copy to the 2.2 directory below
(2) Copy the entire/users/yourmacname/cocos2dx.2.1.4/cocos2d-x-2.1.4/template/xcode4 folder to the corresponding/cocos2dx.2.2.0/ cocos2d-x-2.2.0/template/below
(3) First get the root permissions of the Mac, command line execution install-templates-xcode.sh-u-f, see installed on the upgrade success, XOCDE new project See Cocos2d.cpp is 2.2 version of the;
2, Android Environment installation configuration, jdk,ndk,eclipse after download, organize the following directory, and then start to configure the environment variables under the Mac
The sorted directory is placed under the users root directory:
Open the terminal configuration environment variable and enter the following command:
Vim ~/.bash_profile
Key I, insert edit (if error d is deleted one line)
Modify the following path:
Export path= $PATH:/users/yourmacname/adtformac/sdk/tools?
Export path= $PATH:/users/yourmacname/adtformac/sdk/platform-tools?
Export path= $PATH:/users/yourmacname/android-ndk-r9b/?
Export android_ndk_root=/users/yourmacname/android-ndk-r9b/?
Export ANDROID_SDK_ROOT=/USERS/YOURMACNAME/ADTFORMAC/SDK?
Export ndk_root=/users/yourmacname/android-ndk-r9b/
Copy it in.
Press ESC, and then command to enter the command:
:Wq
3, create a new project
Terminal Open Path/users/yangshengjie/cocos2dx.2.2/cocos2d-x-2.2/tools/project-creator
To create a project with a command:
./create_project.py-project Projectname-package Com.xxx.xxxx-language CPP
Replace your own package name and project name, and the carriage return is successful if established.
You can now open your new project through Xcode, Project catalog in:
/users/yangshengjie/cocos2dx.2.2/cocos2d-x-2.2/projects/mytest
Double-click the folder proj.ios/mytest.xcodeproj can open the project, run directly can run up;
iOS configuration is complete, very simple;
In addition, we recommend a gadget Go2shell (Path command Terminal shortcut tool to the Finder toolbar, a button can be located to open the terminal of this path), this thing icon is also very cute ...
4. Configuring the Android Eclipse Environment
Open the Eclipse,-> import directory/users/yangshengjie/cocos2dx.2.2/cocos2d-x-2.2/cocos2dx/platform/android/java
Load the LIBCOCOS2D project because the new project needs to refer to him as Lib
(1),adt-> Settings->general->workspace->link resources->new dialog box name fill cocos2dx, path selection:/users/yourmacname/ cocos2dx.2.2/cocos2d-x-2.2
Such as:
Ok
(2),adt-> set->ANDROID->SDK location Select your SDK path/USERS/YOURMACNAME/ADTFORMAC/SDK
Such as:
The default SDK comes with a 4.4 rom, APILevel = 19
Ok
(3),adt-> set->android->c/c++->build->environment Add an NDK path/users/yourmacname/android-ndk-r9b
Ok
(4), import the new project/users/yourmacname/cocos2dx.2.2/cocos2d-x-2.2/projects/mytest/proj.android
OK, if the above step is no problem, the import should not be error:
OK, to this step without error, should be able to run directly up, you can plug in the android real machine debugging the following to see how;
Click Run-> your project in Eclipse Consle can be seen as:
We have successfully compiled the. So file through the NDK, and there is no problem on the real machine;
5, write code, cross-platform cross-compilation
Above we have successfully completed the construction of the project and ios,android platform can run up new projects, things are not finished, we have new C + + code, how to cross-compile it? In other words we wrote the code on any of the development platforms in Win32,xcode,eclipse How to sync to other platforms?
Example: I write code in Xcode and then sync it up to eclipse.
I opened the project that I had created before Xcode, which wrote a BaseSoundControl.cpp file, apparently the class is used to control the sound, specific code:
#include "BaseSoundControl.h" #include "SimpleAudioEngine.h" Basesoundcontrol::basesoundcontrol (ccstring* Videourl, BOOL Repetflag) { cocosdenshion::simpleaudioengine::sharedengine ()->preloadbackgroundmusic (videourl-> Getcstring ()); Cocosdenshion::simpleaudioengine::sharedengine ()->playbackgroundmusic (Videourl->getcstring (), repetflag); }
Use the cocosdenshion,win32 below if the use of sound needs to manually add, andriod the newly created project to be added manually;
Xcode iOS runs with the following effects:
First copy the code to the corresponding project, copy the time to note the corresponding directory relationship, such as classes and resources corresponding to all the things (C + + code and pictures, and audio files) are copied over;
Then F5 refresh our Android project, we will see the MyTest Project Classes folder synchronization on the C + + code we write;
Do not worry about the direct run, will error, because in the Android construction works no cocos2d-x inside the Cocosdenshion library dedicated to processing sound cross-platform, manually add it;
Project name-right button->new->folder
Advanced->link to~~~->varivbels, select cocos2dx->extend-> select Cocosdendhion ok! such as:
In the end Filsh had the library;
Not yet, the point of Run will be an error, and the most important step to write. mk File!!!
Eclipse directly in the JNI open the Android.mk file, make the following changes, later wrote a CPP on the configuration of one here;
OK, all the work is done, you can order a run!!
Build again. So success, marking cross-platform compilation run up!
Environment configuration under the Cocos2dx-mac