^_^

2012年12月31日星期一

Mac 下配置 Android NDK 环境并搭建 Cocos2d-x 环境

首先下载和安装基本软件:
  • 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
foolmbp:~ foolbear$ pwd
/Users/foolbear
foolmbp:~ foolbear$ vi .bash_profile
编辑 .bash_profile 文件为(注意对应上面的路径):
export ANDROID_SDK_ROOT=/Users/foolbear/Documents/adt-bundle-mac-x86_64/sdk/
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
关闭当前“终端”并新开一个,下面我们要尝试编译 Cocos2dx 自带的 Sample - TestCpp:
foolmbp:~ foolbear$ cd $COCOS2DX_ROOT
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'
编译成功后,打开 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 进来即可。

选中 TestCpp 项目,右键 - Run As - Android Application 既能在真机中运行。
本站文章除注明外,均为本站原创
转载请注明文章转载自: 大笨熊乐园 [ https://blog.foolbear.com/?m=0 ]
文章标题: Mac 下配置 Android NDK 环境并搭建 Cocos2d-x 环境
文章地址: https://blog.foolbear.com/2012/12/mac-android-ndk-cocos2d-x.html?m=0

没有评论 :

发表评论

Related Posts with Thumbnails