设置编译配置
进入cocos2d-x根目录,执行
./setup.py
会提示输入NDK ANT SDK 路径。
记得执行 source ~/.bash_profile 来更新配置
成功后在用户目录下的.bash_profile 会追加以下信息。
# Add environment variable COCOS_CONSOLE_ROOT for cocos2d-x
export COCOS_CONSOLE_ROOT=/Users/baodong/__DEV__/cocos2d-x-3.6/tools/cocos2d-console/bin
export PATH=$COCOS_CONSOLE_ROOT:$PATH
# Add environment variable COCOS_TEMPLATES_ROOT for cocos2d-x
export COCOS_TEMPLATES_ROOT=/Users/baodong/__DEV__/cocos2d-x-3.6/templates
export PATH=$COCOS_TEMPLATES_ROOT:$PATH
# Add environment variable ANDROID_SDK_ROOT for cocos2d-x
export ANDROID_SDK_ROOT=/Users/baodong/Library/Android/sdk
export PATH=$ANDROID_SDK_ROOT:$PATH
export PATH=$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH
# Add environment variable ANT_ROOT for cocos2d-x
export ANT_ROOT=/Users/baodong/__DEV__/apache-ant-1.9.5/bin
export PATH=$ANT_ROOT:$PATH
# Add environment variable NDK_ROOT for cocos2d-x
export NDK_ROOT=/Users/baodong/__DEV__/android-ndk-r10e
export PATH=$NDK_ROOT:$PATH
备注:
- SDK路径可在SDK manager里找到;
- NDK官网下载为一个bin文件,需要执行 ./android-ndk-r10e.bin,自动解压,从300M+一下展开为3G+ ,注意SSD空间呀~~
- ant从官网直接下载二进制文件,解压即可。
用ADT打开项目
『貌似还不支持AS』
ADT导入现有Android项目,路径类似为 /Users/baodong/TEST/Cocos_TEST/HelloCC/proj.android/
手动拷贝/Users/baodong/DEV/cocos2d-x-3.6/cocos/platform/android/java/src 下的包到项目的src目录下,最终项目如下图所示: