中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MAC下Android Studio 1.4編譯構建Cocos2d-x 3.9之Android版本程序

發布時間:2020-07-06 18:16:42 來源:網絡 閱讀:2222 作者:googlingman 欄目:游戲開發


      本文記載的是一個HELLO WORLD級別的入門程序在如題所示環境下的編譯構建過程。

      說明:如今安裝Android Studio 1.4,它會自動安裝Gradle 2.4(早期卻不是這樣),但遺憾的是沒有下載對應的.zip文件。所以,后面在命令行編譯時還需要再次下載這個文件。

另外,在MAC環境下下載安裝Cocos2d-x 3.9Android Studio 1.4的步驟,在此省略描述。

環境變量配置

終端工具下,運行如下命令:

vim ~/.bash_profile

輸入如下內容:

ANT_ROOT='/usr/local/Cellar/ant/1.9.6/bin'

exportANT_ROOT

COCOS_PATH='~/Downloads/cocos2d-x-3.9/tools/cocos2d-console/bin'

exportCOCOS_PATH

exportPATH=$PATH:$COCOS_PATH:$ANT_ROOT

exportPATH=$PATH:/Users/zxzpc/Library/Android/sdk/tools

exportPATH=$PATH:/Users/zxzpc/LIbrary/Android/sdk/build-tools

exportPATH=$PATH:/Users/zxzpc/Downloads/android-ndk-r10e

exportPATH=$PATH:/Users/zxzpc/usr/local/Cellar/ant/1.9.6/bin

 

exportANDROID_SDK_ROOT=/Users/zxzpc/Library/Android/sdk

exportANDROID_NDK_ROOT=/Users/zxzpc/Downloads/android-ndk-r10e

exportNDK_ROOT=/Users/zxzpc/Downloads/android-ndk-r10e

 

#Add gradle variable export

GRADLE_HOME='/Applications/Android\Studio.app/Contents/gradle/gradle-2.4/bin'

exportPATH=$PATH:$GRADLE_HOME

 

接下來運行下面命令:

source ~/.bash_profile

注意,這里的source命令用于重新執行剛剛修改的系統環境配置文件,使之內容立即生效,而不必注銷并重新登錄。這一點很重要;這樣以后,從命令行下執行cocos命令,它就能夠自動找到上述SDK所在位置。

Android Studio 1.4下打開工程與修改文件gradle-wrapper.properties

啟動Android Studio 1.4打開示例工程MyHelloWorld(使用命令“File”“Open”打開文件夾proj.android-studio即可)。因為文件gradle-wrapper.properties在后期命令行編譯時使用到,所以需要根據實際情況進行修改。初始內容如下:

#Fri Jul 31 20:40:49 CST 2015

distributionBase=GRADLE_USER_HOME

distributionPath=wrapper/dists

zipStoreBase=GRADLE_USER_HOME

zipStorePath=wrapper/dists

distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

但是,我在第一次命令行編譯時出現網絡連接錯誤。大致的意思是,連接不到上面一行指定的網址,這種原因估計一般程序員都知道。于是,根據網絡上的提示,我想也把文件gradle-2.4-all.zip下載到本地,并修改上面的distributionUrl參數。

文件gradle-2.4-all.zip下載倒不是難事,大家可以參考本文后面的下載網址。但是,修改文件倒是出現麻煩了。修改后內容如下:

#Fri Jul 31 20:40:49 CST 2015

distributionBase=GRADLE_USER_HOME

distributionPath=wrapper/dists

zipStoreBase=GRADLE_USER_HOME

zipStorePath=wrapper/dists

#distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

distributionUrl==file\:/Users/zxzpc/Downloads/gradle-2.4-all.zip

但是,接下來,再次在命令行運行命令cocos compile -p android --android-studio時,還是出現錯誤,如下所示:

——————————————————————————————

編譯模式:debug

使用 Android Studio 工程:/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio

未指定 Android 目標平臺版本,自動查找一個可用版本...

正在執行:'/Users/zxzpc/Library/Android/sdk/tools/android update project -tandroid-10 -p /Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app'

 

Updated project.properties

Updated local.properties

Updated file/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app/proguard-project.txt

正在執行 ndk-build...

NDK 編譯模式:debug

NDK_TOOLCHAIN_VERSION: 4.9

正在執行:'/Users/zxzpc/Downloads/android-ndk-r10e/ndk-build -C/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app -j4NDK_MODULE_PATH=/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/../cocos2d:/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/../cocos2d/cocos:/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/../cocos2d/externalNDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1'

 

make: Entering directory`/Users/zxzpc/Documents/MyHelloWorld/proj.android-

 

。。。。。。。。。。(省略)

 

[armeabi] Install        : libcocos2dcpp.so =>libs/armeabi/libcocos2dcpp.so

make: Leaving directory`/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app'

正在生成 apk 文件...

正在執行:'"/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/gradlew"--parallel --info assembleDebug'

 

Exception in thread "main"java.lang.RuntimeException: Could not load wrapper properties from'/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/gradle/wrapper/gradle-wrapper.properties'.

       atorg.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:65)

       atorg.gradle.wrapper.WrapperExecutor.forWrapperPropertiesFile(WrapperExecutor.java:49)

       atorg.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:47)

Caused by: java.net.URISyntaxException: Illegalcharacter in scheme name at index 0:=file:/Users/zxzpc/Downloads/gradle-2.4/gradle-2.4-all.zip

       atjava.net.URI$Parser.fail(URI.java:2829)

       atjava.net.URI$Parser.checkChars(URI.java:3002)

       atjava.net.URI$Parser.checkChar(URI.java:3012)

       atjava.net.URI$Parser.parse(URI.java:3028)

       atjava.net.URI.<init>(URI.java:595)

       atorg.gradle.wrapper.WrapperExecutor.readDistroUrl(WrapperExecutor.java:82)

       atorg.gradle.wrapper.WrapperExecutor.prepareDistributionUri(WrapperExecutor.java:71)

       atorg.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:59)

       ...2 more

執行命令出錯,返回值:1

——————————————————————————————

問題顯然出在『Illegal character in schemename at index 0』這一句。

就是這個問題上,我糾結了不少時間,盡管這種錯誤提示看起來并不復雜。因為實在沒有多少這方面的經驗,所以問題停留在:在.zip文件內容出現問題,還是上面引用本機文件格式出現問題?

再次修改文件與命令行下成功編譯

經過不斷嘗試與借鑒網絡查詢結果,最終我還是把上面文件內容還原到最初狀態,如下所示:

#Fri Jul 31 20:40:49 CST 2015

distributionBase=GRADLE_USER_HOME

distributionPath=wrapper/dists

zipStoreBase=GRADLE_USER_HOME

zipStorePath=wrapper/dists

distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

 

 

再次啟動MAC終端,CD到示例工程HELLOWORLD目錄下,然后執行如下命令:

cocos compile -p android --android-studio

顯示及輸出內容如下:

————————————————————————————————-

編譯模式:debug

使用 Android Studio 工程:/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio

未指定 Android 目標平臺版本,自動查找一個可用版本...

正在執行:'/Users/zxzpc/Library/Android/sdk/tools/android update project -tandroid-10 -p /Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app'

 

Updated project.properties

Updated local.properties

Updated file/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app/proguard-project.txt

正在執行 ndk-build...

NDK 編譯模式:debug

NDK_TOOLCHAIN_VERSION: 4.9

正在執行:'/Users/zxzpc/Downloads/android-ndk-r10e/ndk-build -C/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app -j4NDK_MODULE_PATH=/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/../cocos2d:/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/../cocos2d/cocos:/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/../cocos2d/externalNDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1'

 

make: Entering directory`/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app'

/Users/zxzpc/Downloads/android-ndk-r10e/build/core/build-binary.mk:466:warning: overriding commands for target`obj/local/armeabi/objs-debug/bullet_static/BulletMultiThreaded/SpuLibspe2Support.o'

/Users/zxzpc/Downloads/android-ndk-r10e/build/core/build-binary.mk:466:warning: ignoring old commands for target`obj/local/armeabi/objs-debug/bullet_static/BulletMultiThreaded/SpuLibspe2Support.o'

[armeabi] StaticLibrary  : libcocos2d.a

[armeabi] StaticLibrary  : libcocostudio.a

[armeabi] StaticLibrary  : libcocosbuilder.a

[armeabi] StaticLibrary  : libcocos3d.a

[armeabi] StaticLibrary  : libspine.a

[armeabi] StaticLibrary  : libui.a

[armeabi] StaticLibrary  : libcocosdenshion.a

[armeabi] StaticLibrary  : flatbuffers.a

[armeabi] StaticLibrary  : libextension.a

[armeabi] StaticLibrary  : libaudioengine.a

[armeabi] StaticLibrary  : libbox2d.a

[armeabi] StaticLibrary  : libnetwork.a

[armeabi] StaticLibrary  : libcocos2dxinternal.a

[armeabi] StaticLibrary  : librecast.a

[armeabi] StaticLibrary  : libbullet.a

[armeabi] StaticLibrary  : libcocos2dandroid.a

[armeabi] StaticLibrary  : libcpufeatures.a

[armeabi] Gdbserver      : [arm-linux-androideabi-4.9]libs/armeabi/gdbserver

[armeabi] Gdbsetup       : libs/armeabi/gdb.setup

[armeabi] SharedLibrary  : libcocos2dcpp.so

[armeabi] Install        : libcocos2dcpp.so =>libs/armeabi/libcocos2dcpp.so

make: Leaving directory`/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app'

正在生成 apk 文件...

正在執行:'"/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/gradlew"--parallel --info assembleDebug'

 

Downloadinghttps://services.gradle.org/distributions/gradle-2.4-all.zip

.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Unzipping/Users/zxzpc/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0/gradle-2.4-all.zipto /Users/zxzpc/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0

Set executable permissions for:/Users/zxzpc/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0/gradle-2.4/bin/gradle

Starting Build

Settings evaluated using settings file'/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/settings.gradle'.

Projects loaded. Root project using buildfile '/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/build.gradle'.

Included projects: [root project'proj.android-studio', project ':MyHelloWorld', project ':libcocos2dx']

Parallel execution is an incubatingfeature.

Evaluating root project'proj.android-studio' using build file'/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/build.gradle'.

Downloadhttps://jcenter.bintray.com/com/android/tools/build/gradle/1.3.0/gradle-1.3.0.pom

Downloadhttps://jcenter.bintray.com/com/android/tools/build/gradle-core/1.3.0/gradle-core-1.3.0.pom

Downloadhttps://jcenter.bintray.com/com/android/tools/build/builder/1.3.0/builder-1.3.0.pom

Downloadhttps://jcenter.bintray.com/com/android/tools/lint/lint/24.3.0/lint-24.3.0.pom

//……………………………………..(a lot more, omitted)

Downloadhttps://jcenter.bintray.com/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar

Downloadhttps://jcenter.bintray.com/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar

Downloadhttps://jcenter.bintray.com/commons-codec/commons-codec/1.4/commons-codec-1.4.jar

Downloadhttps://jcenter.bintray.com/com/android/tools/external/lombok/lombok-ast/0.2.3/lombok-ast-0.2.3.jar

Evaluating project ':MyHelloWorld' usingbuild file'/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app/build.gradle'.

Creating configuration compile.

Creating configuration apk.

Creating configuration provided.

Creating configuration wearApp.

Creating configuration androidTestCompile.

Creating configuration androidTestApk.

Creating configuration androidTestProvided.

Creating configuration androidTestWearApp.

Creating configuration testCompile.

Creating configuration testApk.

Creating configuration testProvided.

Creating configuration testWearApp.

Creating configuration debugCompile.

Creating configuration debugApk.

Creating configuration debugProvided.

Creating configuration debugWearApp.

Creating configuration testDebugCompile.

Creating configuration testDebugApk.

Creating configuration testDebugProvided.

Creating configuration testDebugWearApp.

Creating configuration releaseCompile.

Creating configuration releaseApk.

Creating configuration releaseProvided.

Creating configuration releaseWearApp.

Creating configuration testReleaseCompile.

Creating configuration testReleaseApk.

Creating configuration testReleaseProvided.

Creating configuration testReleaseWearApp.

Evaluating project ':libcocos2dx' usingbuild file '/Users/zxzpc/Documents/MyHelloWorld/cocos2d/cocos/platform/android/libcocos2dx/build.gradle'.

Creating configuration compile.

Creating configuration publish.

//……………………………………..(a lot more, omitted)

Creating configuration testReleaseWearApp.

All projects evaluated.

Selected primary task 'assembleDebug' fromproject :

Tasks to be executed: [task':MyHelloWorld:preBuild', task ':MyHelloWorld:preDebugBuild', task':MyHelloWorld:checkDebugManifest', task ':MyHelloWorld:preReleaseBuild', task':libcocos2dx:compileLint', task ':libcocos2dx:copyReleaseLint', task':libcocos2dx:mergeReleaseProguardFiles', task ':libcocos2dx:preBuild', task':libcocos2dx:preReleaseBuild', task ':libcocos2dx:checkReleaseManifest', task':libcocos2dx:prepareReleaseDependencies', task':libcocos2dx:compileReleaseAidl', //……………………………………..(a lot more, omitted)

:MyHelloWorld:zipalignDebug

Executing task':MyHelloWorld:zipalignDebug' (up-to-date check took 0.063 secs) due to:

 Input file/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app/build/outputs/apk/MyHelloWorld-debug-unaligned.apkhas changed.

Starting process 'command'/Users/zxzpc/Library/Android/sdk/build-tools/21.1.2/zipalign''. Working directory:/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app Command:/Users/zxzpc/Library/Android/sdk/build-tools/21.1.2/zipalign -f 4/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app/build/outputs/apk/MyHelloWorld-debug-unaligned.apk/Users/zxzpc/Documents/MyHelloWorld/proj.android-studio/app/build/outputs/apk/MyHelloWorld-debug.apk

Successfully started process 'command'/Users/zxzpc/Library/Android/sdk/build-tools/21.1.2/zipalign''

:MyHelloWorld:zipalignDebug (Thread[Taskworker,5,main]) completed. Took 0.16 secs.

:MyHelloWorld:assembleDebug (Thread[Taskworker,5,main]) started.

:MyHelloWorld:assembleDebug

Skipping task ':MyHelloWorld:assembleDebug'as it has no actions.

:MyHelloWorld:assembleDebug (Thread[Taskworker,5,main]) completed. Took 0.0 secs.

 

BUILD SUCCESSFUL

 

Total time: 19 mins 12.95 secs

Stopped 0 compiler daemon(s).

 

This build could be faster, please considerusing the Gradle Daemon:http://gradle.org/docs/2.4/userguide/gradle_daemon.html

正在移動 apk 文件 /Users/zxzpc/Documents/MyHelloWorld/bin/debug/android

編譯成功。

————————————————————————————————


顯然,下載gradle-2.4-all.zip和相應解壓花費了不少時間,但總算有了一個初步的驚喜。而且,如讀者所想,使用本地的文件是節約時間的最佳辦法。無奈,拙人我現在還沒有找到。以后找到,一定記錄下來。


剩下的好辦了,把生成的APK文件設法復制到我的三星I9100機器上(還是Android 2.3.4版本)。安裝運行即可,截圖如下:

 

MAC下Android Studio 1.4編譯構建Cocos2d-x 3.9之Android版本程序

注意:圖中中文顯示不正常,是因為我沒有作相應處理而已。

小結

Android Studio 1.4編譯與構建速度比Eclipse快幾十倍,模擬器啟動速度也快得多。盡管我的編譯工程不是在IDE環境下實現的。

命令行編譯還是更迅速,值得推薦。

本次記錄的是MAC環境命令行下的編譯生成APK文件的過程。走了不少曲折的路,記錄下來供自己備忘,也供同志們參考。

引用

 

  • Gradle下載頁面:http://services.gradle.org/distributions。非常全面,值得推薦。

 

 

 


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

海晏县| 台前县| 五指山市| 平谷区| 阳原县| 青浦区| 田东县| 安远县| 和顺县| 鲁甸县| 浙江省| 拉萨市| 鄄城县| 紫阳县| 阿荣旗| 三门峡市| 静海县| 万载县| 福泉市| 两当县| 肥西县| 平顶山市| 疏勒县| 临潭县| 祁连县| 中山市| 卫辉市| 乌兰察布市| 麦盖提县| 台江县| 永顺县| 江西省| 商都县| 龙陵县| 将乐县| 巴林右旗| 名山县| 依安县| 饶平县| 铜川市| 凌海市|