+44(0) 1234 567 890 info@domainname.com

November 09, 2013

cocos2d-x for Android on Linux, Getting Started

7:56 AM

Share it Please
This is my step by step when I ran out example of HelloCpp cocos2d-x project for Android on linux operating system. Here, I use openSUSE 12.3 or fedora 19 64-bit (dual boot).

1. Install Eclipse + Android SDK + Android NDK
2. Setting path NDK_ROOT
- Open .bash_profile file
 vim /home/kirman/.bash_profile [enter]

- Add NDK_ROOT to .bash_profile file
 export NDK_ROOT=/home/kirman/android-ndk-r8d

3. Download cocosd-x (in this case, version 2.2) and extract it, then this path of cocos2d-x is called by $cocos2d_home. Then, go to $cocos2d_home/template/multi-platform-cpp/proj.android by command line and run build_native.sh script.
 ./build_native.sh [enter]

If this script is running, so our path environment of NDK_ROOT is correct. But, if you got message to specify of NDK_ROOT, you should to corrects NDK_ROOT path. This is example when I ran build_native.sh script
 [kirman@kirmanz proj.android]$ ./build_native.sh 
NDK_ROOT = /home/kirman/android-ndk-r8d
COCOS2DX_ROOT = /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android/../../..
APP_ROOT = /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android/..
APP_ANDROID_ROOT = /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android
Using prebuilt externals
make: Entering directory `/home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android'
Compile++ thumb  : cocos2dcpp_shared <= main.cpp
Compile++ thumb  : cocos2dcpp_shared <= AppDelegate.cpp
Compile++ thumb  : cocos2dcpp_shared <= HelloWorldScene.cpp
Prebuilt       : libgnustl_static.a <= /sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/
Compile++ thumb  : cocos2dx_static <= CCConfiguration.cpp
Compile++ thumb  : cocos2dx_static <= CCScheduler.cpp
Compile++ thumb  : cocos2dx_static <= CCCamera.cpp
Compile thumb  : cocos2dx_static <= ccFPSImages.c
Compile++ thumb  : cocos2dx_static <= CCAction.cpp
...........................

Compile++ thumb  : cocos_extension_static <= CCSkeleton.cpp
Compile++ thumb  : cocos_extension_static <= spine-cocos2dx.cpp
Prebuilt       : curl.a <= /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android/../../../cocos2dx/platform/third_party/android/prebuilt/libcurl/libs/armeabi/
Prebuilt       : libwebsockets_static.a <= /home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android/../../../external/libwebsockets/android/./lib/armeabi/
StaticLibrary  : libextension.a
SharedLibrary  : libcocos2dcpp.so
Install        : libcocos2dcpp.so => libs/armeabi/libcocos2dcpp.so
make: Leaving directory `/home/kirman/cocos2d-x-2.2/template/multi-platform-cpp/proj.android'

4. Open Eclipse and setting CPU/ABI of Android Virtual Device (AVD) Manager to ARM(armeabi-v7a) and don't forget to check "Use Host GPU"

5. Import library of cocos2dx to Eclipse. File->Import -> Android -> Existing Android Code Into Workspace -> Browse to $cocos2d_home/cocos2dx/platform/android. Here, we have imported our needed to run project apps.

6. Import HelloCpp project of cocos2dx from $cocosd_home/template/multi-platform-cpp/proj.android.
File -> new -> Other -> Android -> Android Project from Existing Code -> Browse to $cocosd_home/template/multi-platform-cpp/proj.android 
If your step is corrected, you will not get any messages error until this way.

7. Run HelloCpp project apps to AVD emulator that we have created before. Here my screenshot of this project example. 


0 komentar: