In front of a period of time only Cocos2d-x in IOS platform development, learning Cocos2d-x is not for his cross-platform features? Therefore, we must also master the development under Android, In order to detonate the cross-platform characteristics of Cocos2d-x, play its biggest strengths.
Cocos2d-x version development is very fast, and in the development environment of Android + Eclipse configuration super complex, very pitfall have wood ah ????
If you find something different, it may be caused by different versions. Of course, it may be because I made a mistake.
Version:
Cocos2d-x: cocos2d-2.0-x-2.0.3
OS X: 10.8
Xcode: 4.5.1
Eclipse: 4.2.1
NDK: android-ndk-r8b
Device: Samsung T959 cm10 (Android 4.1.2)
File Path:
Cocos2d-x:/opt/cocos2d-2.0-x-2.0.3
Android SDK:/opt/android-sdk-macosx
Android NDK:/opt/android-ndk-r8b
If you refer to these paths below, replace them with your own paths.
1. Configure the Cocos2d-x for Xcode.
This is relatively simple. For more information, see other articles.
Key: install-templates-xcode.sh
2. Configure the General Android Development Environment
This part includes JDK installation, Eclipse installation, and ADT installation. There are many tutorials.
3. Install CDT in Eclipse, that is, the C ++ Development Environment
4. Set environment variables, that is, edit ~ /. Bash_profile
Add in
export COCOS2DX_ROOT=/opt/cocos2d-2.0-x-2.0.3export ANDROID_SDK_ROOT=/opt/android-sdk-macosxexport ANDROID_NDK_ROOT=/opt/android-ndk-r8bexport NDK_ROOT=/opt/android-ndk-r8bexport PATH=$PATH:$ANDROID_NDK_ROOTexport PATH=$PATH:$ANDROID_SDK_ROOT
5. Create an Android project named "CCTest ".
Youngs-MacBook-Air:~ young40$ cd /opt/cocos2d-2.0-x-2.0.3/Youngs-MacBook-Air:cocos2d-2.0-x-2.0.3 young40$ ./create-android-project.sh use global definition of NDK_ROOT: /opt/android-ndk-r8buse global definition of ANDROID_SDK_ROOT: /opt/android-sdk-macosxInput package path. For example: org.cocos2dx.examplecom.young40Now cocos2d-x supports Android 2.2 or upper versionAvailable Android targets:----------id: 1 or "android-3" Name: Android 1.5 Type: Platform API level: 3 Revision: 4 Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P ABIs : armeabi----------id: 2 or "android-10" Name: Android 2.3.3 Type: Platform API level: 10 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854 ABIs : armeabi----------id: 3 or "android-15" Name: Android 4.0.3 Type: Platform API level: 15 Revision: 3 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800 ABIs : armeabi-v7a, x86----------id: 4 or "android-16" Name: Android 4.1 Type: Platform API level: 16 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in ABIs : armeabi-v7ainput target id:2input your project name:CCTestCreated project directory: /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.androidCreated directory /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/src/com/young40Added file /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/src/com/young40/CCTest.javaCreated directory /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/resCreated directory /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/binCreated directory /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/libsCreated directory /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/res/valuesAdded file /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/res/values/strings.xmlCreated directory /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/res/layoutAdded file /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/res/layout/main.xmlAdded file /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/AndroidManifest.xmlAdded file /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/build.xmlAdded file /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/proguard-project.txtResolved location of library project to: /opt/cocos2d-2.0-x-2.0.3/cocos2dx/platform/android/javaUpdated project.propertiesUpdated local.propertiesUpdated file /opt/cocos2d-2.0-x-2.0.3/CCTest/proj.android/proguard-project.txtYoungs-MacBook-Air:cocos2d-2.0-x-2.0.3 young40$
6. Compile the default C ++ Resources
Youngs-MacBook-Air: proj. android young40 $ cd/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android/Youngs-MacBook-Air: proj. android young40 $. /build_native.sh NDK_ROOT =/opt/android-ndk-r8bCOCOS2DX_ROOT =/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android /.. /.. APP_ROOT =/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android /.. APP_ANDROID_ROOT =/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. androidUsing prebuilt externalsmake: Entering directory '/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android 'gdbserver: [arm-linux-androideabi-4.6] libs/armeabi/gdbserverGdbsetup: libs/armeabi/gdb. setupCompile ++ thumb: game_shared <= main. cppIn file written ded from/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android/http://www.cnblogs.com/cocos2dx/platform/android/jni/JniHelper.h:27:0, from jni/hellocpp/main. cpp: 2:/opt/android-ndk-r8b/platforms/android-14/arch-arm/usr/include/jni. h: 592: 13: note: the mangling of 'va _ List' has changed in GCC 4.4 Compile ++ thumb: game_shared <= AppDelegate. cppCompile ++ thumb: game_shared <= HelloWorldScene. cppPrebuilt: libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc ++/4.6/libs/armeabi/Compile ++ thumb: cocos2dx_static <= CCConfiguration. cpp ..... the intermediate compilation output omitted Prebuilt: curl. a & lt; =/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android/http://www.cnblogs.com/cocos2dx/platform/third_party/android/prebuilt/libcurl/libs/armeabi/StaticLibrary: libextension. aSharedLibrary: libgame. soInstall: libgame. so => libs/armeabi/libgame. somake: Leaving directory '/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android'
7. Create an Eclipse project and run the default Demo
, Select Android Project from Existing Code.
Address selection:/opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android (direct input may report an error, please select the directory with the mouse)
Click Next to add the project to Eclipse. However, an error is reported for the project.
The import org.cocos2dx.lib cannot be resolved CCTest.java /com.young40.CCTest/src/com/young40 line 26 Java ProblemCocos2dxActivity cannot be resolved to a type CCTest.java /com.young40.CCTest/src/com/young40 line 30 Java ProblemCocos2dxActivity cannot be resolved to a type CCTest.java /com.young40.CCTest/src/com/young40 line 33 Java Problem
My solution is:
/opt/cocos2d-2.0-x-2.0.3/cocos2dx/platform/android/java
You can add a project to solve the error.
8. Compile and run
An error occurred while running the project on the Virtual Machine Android2.3.3.
It doesn't matter. I use a real machine to test. adb wireless connection to the real machine (cm10 is good, comes with wireless debugging)
Youngs-MacBook-Air:proj.android young40$ /opt/android-sdk-macosx/platform-tools/adb connect 192.168.8.139:5555connected to 192.168.8.139:5555
OK. The operation is successful ,.
FPS is a little low. My ipad2 can reach 60 frames at full speed.
9. Create an Xcode project named CCTest.
After creation, you can run the test.
Delete the Classes directory under the project
Then add the directory/opt/cocos2d-2.0-x-2.0.3/CCTest/Classes to the project. Make sure that Destination is not selected. The Code will exist in the project as a reference.
Modify HelloWorldScene. cpp under Classes and run the test.
CCLabelTTF* pLabel = CCLabelTTF::create("Hello Cocos2d-x!", "Thonburi", 34);
Successful. The version of cocos2d-x 2.0.3 has a problem of orientation rotation on ios6, it should be landscape.
10. Run it again in Android.
First run:
/Opt/cocos2d-2.0-x-2.0.3/CCTest/proj. android/build_native.sh
In the Eclipse menu, select Project => Clean to clear the Project, and Run the Project. You can see that the change has taken effect on your phone.
11. Do you think the previous step is cumbersome? Can I click Run to compile C ++ resources at the same time? The answer is yes.
Select the CCTest project on the left side of Eclipse, right-click New => Other,
In the displayed dialog box, select C/C ++ => Convert to a C/C ++ Proejct (Adds C/C ++ Nature)
On the next screen, set C ++ Project and Project Type to Makefile project, and Toolchains to Other.
Next, Eclipse will ask if you want to switch to the C ++ view and select "no". If you accidentally switch over, switch back to the java view.
Open the project properties page and set to automatically compile C ++ ,:
Note that you must change the Build command to the project name.
Bash $ {workspace_loc:/com. young40.CCTest}/build_native.sh NDK_DEBUG = 1 V = 1
Click Run. An error is reported here. The compilation prompt is "please define NDK_ROOT". You need to add the environment variable in the Project Settings.
Click Run again, and the Console window will show the compiled output. The compilation is successful. The operation is successful.
12. Eliminate error messages in Eclipse.
If you open the hellocpp/main. cpp file under the project jni directory, you will see a large number of errors. We need to add relevant files to the project.
Add/opt/cocos2d-2.0-x-2.0.3/CCTest/Classes to the project first. Add a Link-type folder.
Add "/opt/cocos2d-2.0-x-2.0.3/cocos2dx" to the project in the same way.
Then add reference.
/Opt/android-ndk-r8b/platforms/android-8/arch-arm/usr/include
/Opt/cocos2d-2.0-x-2.0.3/CocosDenshion/include
This is slightly different from the document practices of a foreigner translated by Zilong mountain. He still reports many errors in that method, which may be caused by different versions.
I do not need to ignore the file in this method. I can click the class to see the corresponding declaration.
In this way, the initial IOS and Android development environment is integrated.
If you have any questions, please contact us.
My weibo: http://weibo.com/young40
Refer:
1. cocos2d-x cross android & ios platform development tutorial
Http://www.cnblogs.com/zilongshanren/archive/2012/04/28/2473282.html