新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Cocos2d-x學(xué)習(xí)之創(chuàng)建Android工程和編譯

Cocos2d-x學(xué)習(xí)之創(chuàng)建Android工程和編譯

作者: 時(shí)間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

安裝好,相應(yīng)的環(huán)境之后,我們便可以開始創(chuàng)建cocos2d-x 的android 工程了

本文引用地址:http://m.butianyuan.cn/article/201610/305430.htm

進(jìn)入cocs2d-x目錄,用文本編輯器打開create-android-project.bat(在windows 7上如果正常雙擊,可能創(chuàng)建時(shí)有些文件的權(quán)限不足,導(dǎo)致創(chuàng)建工程不成,可以在此文件的第一行加上cd /d %~dp0,然后右鍵以管理員身份運(yùn)行)

找到以下幾個(gè)定義:

復(fù)制代碼

@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

復(fù)制代碼

將_CYGBIN=設(shè)置為cycgwinbin安裝的的絕對路徑。

將_ANDROIDTOOLS設(shè)置為android sdk 的tools絕對路徑

將_NDKROOT設(shè)置為android ndk的絕對路徑

修改完畢,保存后

雙擊create-android-project.bat開始工程創(chuàng)建向?qū)?/p>

首先是輸入包名(建議按照android的命名規(guī)則),如com.android.test

然后輸入工程名稱(注意不要輸入已有的文件夾的名字,如果同名,會(huì)被覆蓋掉的),如testandroid,如下圖:

wps_clip_image-15949

然后選擇target id,

wps_clip_image-14424

其會(huì)列出機(jī)器上安裝的所有版本的sdk,我們選擇6,即2.3.2的sdk.

wps_clip_image-2448

進(jìn)入g:cocos2d-x目錄發(fā)現(xiàn)多了一個(gè)名為testandroid的目錄,里面包含三個(gè)目錄

wps_clip_image-19661

其中Classes:是存放默認(rèn)工程的C++文件

proj.android 是android的eclipse工程項(xiàng)目

Resources 資源文件

下來我們開始編譯剛創(chuàng)建的testandroid項(xiàng)目

打開cygwin,進(jìn)入到testandroid/proj.android目錄,輸入 ./build_native.sh 開始編譯如下圖:


上一頁 1 2 3 下一頁

關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉