- ADT Bundle for Mac(这里面已经包含了 Android SDK、Eclipse IDE 及 ADT (Android Developer Tools)),目前版本为 v21.0.1-543035。解压为 /Users/foolbear/Documents/adt-bundle-mac-x86_64,运行 eclipse/eclipse 即可。此时 Android SDK 路径为 /Users/foolbear/Documents/adt-bundle-mac-x86_64/sdk。
- Android NDK for Mac,版本为 r8d。解压为 /Users/foolbear/Documents/android-ndk-r8d,即 Android NDK 路径。
- Cocos2d-x,这里用的是稳定的 cocos2d-2.0-x-2.0.4 版本。解压为 /Users/foolbear/Documents/cocos2d-2.0-x-2.0.4,即 Cocos2d-X 路径。
打开“终端”,输入及回应如下:
foolmbp:~ foolbear$ cd编辑 .bash_profile 文件为(注意对应上面的路径):
foolmbp:~ foolbear$ pwd
/Users/foolbear
foolmbp:~ foolbear$ vi .bash_profile
export ANDROID_SDK_ROOT=/Users/foolbear/Documents/adt-bundle-mac-x86_64/sdk/关闭当前“终端”并新开一个,下面我们要尝试编译 Cocos2dx 自带的 Sample - TestCpp:
export ANDROID_NDK_ROOT=/Users/foolbear/Documents/android-ndk-r8d
export COCOS2DX_ROOT=/Users/foolbear/Documents/cocos2d-2.0-x-2.0.4
export NDK_ROOT=/Users/foolbear/Documents/android-ndk-r8d
export PATH=$PATH:$ANDROID_SDK_ROOT
export PATH=$PATH:$ANDROID_NDK_ROOT
foolmbp:~ foolbear$ cd $COCOS2DX_ROOT编译成功后,打开 Eclipse,File - Import - Android - Existing Android Code Into Workspace,选择 Root Directory 为 /Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/samples/TestCpp/proj.android, Finish。这时会有三个错误,解决方法是将 /Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/cocos2dx/platform/android/java 也同法 import 进来即可。
foolmbp:cocos2d-2.0-x-2.0.4 foolbear$ cd samples/TestCpp/proj.android/
foolmbp:proj.android foolbear$ ./build_native.sh
NDK_ROOT = /Users/foolbear/Documents/android-ndk-r8d
COCOS2DX_ROOT = /Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/samples/TestCpp/proj.android/../../..
APP_ROOT = /Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/samples/TestCpp/proj.android/..
APP_ANDROID_ROOT = /Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/samples/TestCpp/proj.android
Using prebuilt externals
make: Entering directory `/Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/samples/TestCpp/proj.android'
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : testcpp_shared <= main.cpp
Prebuilt : libgnustl_static.a <= <ndk>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/
Compile++ thumb : cocos_testcpp_common <= AccelerometerTest.cpp
Compile++ thumb : cocos_testcpp_common <= ActionManagerTest.cpp
...
Compile++ thumb : cocos_extension_static <= HttpClient.cpp
Prebuilt : curl.a <= /Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/samples/TestCpp/proj.android/../../../cocos2dx/platform/third_party/android/prebuilt/libcurl/libs/armeabi/
StaticLibrary : libextension.a
StaticLibrary : libtestcppcommon.a
SharedLibrary : libtestcpp.so
Install : libtestcpp.so => libs/armeabi/libtestcpp.so
make: Leaving directory `/Users/foolbear/Documents/cocos2d-2.0-x-2.0.4/samples/TestCpp/proj.android'
选中 TestCpp 项目,右键 - Run As - Android Application 既能在真机中运行。
没有评论 :
发表评论