Cocos2d-x學(xué)習(xí)之創(chuàng)建Android工程和編譯
安裝好,相應(yīng)的環(huán)境之后,我們便可以開(kāi)始創(chuàng)建cocos2d-x 的android 工程了
本文引用地址:http://butianyuan.cn/article/201610/305430.htm進(jìn)入cocs2d-x目錄,用文本編輯器打開(kāi)create-android-project.bat(在windows 7上如果正常雙擊,可能創(chuàng)建時(shí)有些文件的權(quán)限不足,導(dǎo)致創(chuàng)建工程不成,可以在此文件的第一行加上cd /d %~dp0,然后右鍵以管理員身份運(yùn)行)
找到以下幾個(gè)定義:
@echo off
:: This script is used to create an android project.
:: You should modify _ANDROIDTOOLS _CYGBIN _NDKROOT to work under your environment.
:: Don't change it until you know what you do.
cd /d %~dp0
setlocal
:: Check if it was run under cocos2d-x root
if not exist %create-android-project.bat echo Error!!! You should run it under cocos2dx root pause exit 2
if not exist %~dpn0.sh echo Script %~dpn0.sh not found pause exit 3
:: modify it to work under your environment
set _CYGBIN=D:cygwinbin
if not exist %_CYGBIN% echo Couldn't find Cygwin at %_CYGBIN% pause exit 4
:: modify it to work under your environment
set _ANDROIDTOOLS=E:android-sdk-windowstools
if not exist %_ANDROIDTOOLS% echo Couldn't find android sdk tools at %_ANDROIDTOOLS% pause exit 5
:: modify it to work under your environment
set _NDKROOT=E:android-ndk-r8-windowsandroid-ndk-r8
if not exist %_NDKROOT% echo Couldn't find ndk at %_NDKROOT% pause exit 6
:: create android project
set /P _PACKAGEPATH=Please enter your package path. For example: org.cocos2dx.example:
set /P _PROJECTNAME=Please enter your project name:
if exist %%_PROJECTNAME% echo %_PROJECTNAME% exists, please use another name pause exit 7
echo Now cocos2d-x suppurts Android 2.1-update1, 2.2, 2.3 3.0
echo Other versions have not tested.
call %_ANDROIDTOOLS%android.bat list targets
set /P _TARGETID=Please input target id:
set _PROJECTDIR=%%_PROJECTNAME%
echo Create android project
call %_ANDROIDTOOLS%android.bat create project -n %_PROJECTNAME% -t %_TARGETID% -k %_PACKAGEPATH% -a %_PROJECTNAME% -p %_PROJECTDIR%
:: Resolve ___.sh to /cygdrive based *nix path and store in %_CYGSCRIPT%
for /f delims= %%A in ('%_CYGBIN%cygpath.exe %~dpn0.sh') do set _CYGSCRIPT=%%A
:: Resolve current dir to cygwin path
for /f delims= %%A in ('%_CYGBIN%cygpath.exe %') do set _CURRENTDIR=%%A
:: Resolve ndk dir to cygwin path
for /f delims= %%A in ('%_CYGBIN%cygpath.exe %_NDKROOT%') do set _NDKROOT=%%A
:: Throw away temporary env vars and invoke script, passing any args that were passed to us
endlocal %_CYGBIN%bash --login %_CYGSCRIPT% %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% %_PACKAGEPATH% windows
pause
將_CYGBIN=設(shè)置為cycgwinbin安裝的的絕對(duì)路徑。
將_ANDROIDTOOLS設(shè)置為android sdk 的tools絕對(duì)路徑
將_NDKROOT設(shè)置為android ndk的絕對(duì)路徑
修改完畢,保存后
雙擊create-android-project.bat開(kāi)始工程創(chuàng)建向?qū)?/p>
首先是輸入包名(建議按照android的命名規(guī)則),如com.android.test
然后輸入工程名稱(注意不要輸入已有的文件夾的名字,如果同名,會(huì)被覆蓋掉的),如testandroid,如下圖:
然后選擇target id,
其會(huì)列出機(jī)器上安裝的所有版本的sdk,我們選擇6,即2.3.2的sdk.
進(jìn)入g:cocos2d-x目錄發(fā)現(xiàn)多了一個(gè)名為testandroid的目錄,里面包含三個(gè)目錄
其中Classes:是存放默認(rèn)工程的C++文件
proj.android 是android的eclipse工程項(xiàng)目
Resources 資源文件
下來(lái)我們開(kāi)始編譯剛創(chuàng)建的testandroid項(xiàng)目
打開(kāi)cygwin,進(jìn)入到testandroid/proj.android目錄,輸入 ./build_native.sh 開(kāi)始編譯如下圖:
評(píng)論