您好,登錄后才能下訂單哦!
今天對cocos2d-x編譯成android做個筆記,本文使用的是2.2.1版本。這里指記錄如何編譯。本文主要參考http://blog.csdn.net/sttyytw/article/details/17005263
1、創(chuàng)建通過python來創(chuàng)建項目
python create_project.py -project helloworld -package com.xzw.game -language cpp
另外提供批處理,方便下次創(chuàng)建:
@echo off :label1 @cls echo 歡迎使用Python創(chuàng)建Cocos2d-x工程 set /p project=請輸入需要創(chuàng)建的工程名: set /p aID=請輸入需要創(chuàng)建的android版本包標識名: echo 您輸入的工程名為%project% echo 您輸入的android版本包標識名為%aID% echo 確認創(chuàng)建工程嗎? CHOICE /C 123 /M "確認請按 1,取消請按 2,或者退出請按 3。" echo %errorlevel% if %errorlevel%==1 goto label2 if %errorlevel%==2 goto label1 if %errorlevel%==3 goto label3 :label2 echo 正在創(chuàng)建工程... python create_project.py -project %project% -package %aID% -language cpp :label3 pause
創(chuàng)建好后會在cocos2d-x-2.2.1\projects目錄下。
2、使用cygwin進入proj.android目錄下,然后執(zhí)行./build_native.sh就可以進行編譯了。
前提是需要對build_natvie.sh進行修改,這樣才能夠自動將所需要cocos2d-x的類加到工程中。
首先在cygwin中添加cocos2d-x的配置
COCOS2DX_DIR=/cygdrive/e/resource/cocos2d-x/cocos2d-x-2.2.1/cocos2d-x-2.2.1 export COCOS2DX_DIR
然后修改cocos2d-x-2.2.1\template\multi-platform-cpp\proj.android下的build_native.sh文件進行修改。如下圖:
APPNAME="HelloCpp" # options buildexternalsfromsource= usage(){ cat << EOF usage: $0 [options] Build C/C++ code for $APPNAME using Android NDK OPTIONS: -s Build externals from source -h this help EOF } while getopts "sh" OPTION; do case "$OPTION" in s) buildexternalsfromsource=1 ;; h) usage exit 0 ;; esac done # paths if [ -z "${NDK_ROOT+aaa}" ];then echo "please define NDK_ROOT" exit 1 fi if [ -z "${COCOS2DX_DIR+aaa}" ];then echo "please define COCOS2DX_DIR" exit 1 fi DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # ... use paths relative to current directory COCOS2DX_ROOT="$DIR/../../.." APP_ROOT="$DIR/.." APP_ANDROID_ROOT="$DIR" echo "COCOS2DX_DIR = $COCOS2DX_DIR" echo "NDK_ROOT = $NDK_ROOT" echo "COCOS2DX_ROOT = $COCOS2DX_ROOT" echo "APP_ROOT = $APP_ROOT" echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT" # make sure assets is exist if [ -d "$APP_ANDROID_ROOT"/assets ]; then rm -rf "$APP_ANDROID_ROOT"/assets fi mkdir "$APP_ANDROID_ROOT"/assets # copy resources for file in "$APP_ROOT"/Resources/* do if [ -d "$file" ]; then cp -rf "$file" "$APP_ANDROID_ROOT"/assets fi if [ -f "$file" ]; then cp "$file" "$APP_ANDROID_ROOT"/assets fi done for file in "$COCOS2DX_DIR"/cocos2dx/platform/android/java/src/* do if [ -d "$file" ]; then cp -rf "$file" "$APP_ANDROID_ROOT"/src fi if [ -f "$file" ]; then cp "$file" "$APP_ANDROID_ROOT"/src fi done # run ndk-build if [[ "$buildexternalsfromsource" ]]; then echo "Building external dependencies from source" "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source" else echo "Using prebuilt externals" "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt" fi
3、eclipse導入比運行
運行即可。就這么就記錄了。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。