怎么将cocos2d-js 3.x 成功在android平台编译打包 (测试ok)

怎么将cocos2d-js 3.x 成功在android平台编译打包 (测试ok),第1张

概述转载:http://www.cocoachina.com/bbs/read.php?tid=209353 1. 环境配置 使用的 *** 作系统是64位的Ubuntu Server 14.04,首先下载cocos2d-js开发包和android必须的NDK、SDK等开发库,有更新的版本请下载新版本,全部解压到/home/magic(本文测试用户目录)下的目录。 cocos2d-js-v3.0-beta.z

转载:http://www.cocoachina.com/bbs/read.PHP?tID=209353

1. 环境配置


使用的 *** 作系统是64位的Ubuntu Server 14.04,首先下载cocos2d-Js开发包和androID必须的NDK、SDK等开发库,有更新的版本请下载新版本,全部解压到/home/magic(本文测试用户目录)下的目录。

cocos2d-Js-v3.0-beta.zip
androID-ndk-r9d-linux-x86_64.tar.bz2
androID-sdk_r22.6.2-linux.tgz
apache-ant-1.9.4-bin.tar.bz2
配置cocos2d-Js:
magic@magic:~$ cd cocos2d-Js-v3.0-beta
magic@magic:~/cocos2d-Js-v3.0-beta$ ./setup.py
Setting up cocos2d-x...
->Check environment variable COCOS_CONSolE_ROOT
->Find environment variable COCOS_CONSolE_ROOT...
->COCOS_CONSolE_ROOT is found : /home/magic/cocos2d-Js-v3.0-beta/tools/cocos2d-console/bin
->Configuration for AndroID platform only,you can also skip and manually edit "/home/magic/.bashrc"
->Check environment variable NDK_ROOT
->Find environment variable NDK_ROOT...
->NDK_ROOT is found : /home/magic/androID-ndk-r9d
->Check environment variable ANDROID_SDK_ROOT
->Find environment variable ANDROID_SDK_ROOT...
->ANDROID_SDK_ROOT is found : /home/magic/androID-sdk-linux
->Check environment variable ANT_ROOT
->Find environment variable ANT_ROOT...
->ANT_ROOT is found : /home/magic/apache-ant-1.9.4/bin/
Please execute command: "source /home/magic/.bashrc" to make added system variables take effect
magic@magic:~/cocos2d-Js-v3.0-beta$ source /home/magic/.bashrc
安装java的运行和开发环境:
magic@magic:~$ sudo apt-get install default-jre
magic@magic:~$ sudo apt-get install default-jdk
进入androID sdk的目录下载更新androID平台和第三方库文件:
magic@magic:~$ cd androID-sdk-linux
magic@magic:~/androID-sdk-linux$ tools/androID update sdk --no-ui
如果不更新,那么用cocos没法编译。这个更新下载时间非常长,会把所有androID版本的sdk文件都下载下来,建议下班前执行,第二天上班再来看。
如果你的 *** 作系统是64位的,那么还需要安装32位的编译器:
magic@magic:~$ sudo apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386 --no-install-recommends
否则后面cocos编译的时候会出现类似如下错误:
BUILD Failed
/home/magic/androID-sdk-linux/tools/ant/build.xml:601: The following error occurred while executing this line:
/home/magic/androID-sdk-linux/tools/ant/build.xml:653: The following error occurred while executing this line:
/home/magic/androID-sdk-linux/tools/ant/build.xml:698: Execute Failed: java.io.IOException: Cannot run program "/home/magic/androID-sdk-linux/build-tools/19.1.0/aapt" (in directory "/home/magic/project/MyGame/frameworks/Js-bindings/cocos2d-x/cocos/platform/androID/java"): error=2,No such file or directory
因为aapt是个32的程序,它要调用32位编译器。
2. 编译测试
生成一个测试项目:
magic@magic:~$ cocos new MyGame -l Js -d /home/magic/project/
修改frameworks/runtime-src/proj.androID/AndroIDManifest.xml可以设置游戏启动是横屏还是竖屏,默认是landscape:
androID:screenorIEntation="portrait"
编译这个测试项目:
magic@magic:~$ cd project/MyGame/
magic@magic:~/project/MyGame$ cocos compile -p androID
...
BUILD SUCCESSFul
Total time: 12 seconds
Move apk to /home/magic/project/MyGame/runtime/androID
build succeeded.
magic@magic:~/project/MyGame$ ls -l /home/magic/project/MyGame/runtime/androID
total 6120
-rw-rw-r-- 1 magic magic 6263119 Jun 16 16:08 MyGame-deBUG.apk

这样编译的是deBUG版本,方便测试调试。一般开发阶段这样已经就可以了。

注意: 如果cocos compile -p androID 出现如下问题:

如题,cocos2dx3.13.1项目编译androID时报错:

AndroID NDK: WARNING: APP_PLATFORM androID-19 is larger than androID:minSdkVersion 9 in ./AndroIDManifest.xml
AndroID NDK:
ERROR:/Users/Evan/documents/androID-ndk/sources/cxx-stl/gnu-libstdc++/AndroID.mk:gnustl_static: LOCAL_SRC_fileS points to a missing file
AndroID NDK: Check that /Users/Evan/documents/androID-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a exists or that its path is correct
make: Entering directory `/Users/Evan/documents/work-fight/Jdysrfight/fightGame/frameworks/runtime-src/proj.androID'
/Users/Evan/documents/androID-ndk/build/core/prebuilt-library.mk:45: *** AndroID NDK: Aborting . Stop.
make: Leaving directory `/Users/Evan/documents/work-fight/Jdysrfight/fightGame/frameworks/runtime-src/proj.androID'

解决方法:我之前用的ndk版本为r9,换成r10c就好了。

备注:/Users/Evan/documents/androID-ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a exists or that its path is correct

注意这里有个4.9/,r9d里只有4.6,4.8没有4.9的,所以暂时是换了ndk版本解决的。

ndk 下载地址:https://developer.androID.Google.cn/ndk/downloads/revision_history.HTML




3. 发布release版本
如果要编译release版本,那么首先要创建keystore:
magic@magic:~/project/MyGame$ keytool -genkey -alias demo.keystore -keyalg RSA -valIDity 3650 -keystore demo.keystore
说明:
genkey 产生密钥
-alias demo.keystore 别名 demo.keystore
-keyalg RSA 使用RSA算法对签名加密
-valIDity 3650 有效期限10年
-keystore demo.keystore
会要求输入keystore的密码,以及组织名字等相关信息,填好后在当前目录生成keystore文件:
magic@magic:~/project/MyGame$ ls -l demo.keystore
-rw-rw-r-- 1 magic magic 2195 Jun 17 09:04 demo.keystore
然后用如下命令编译发布:
magic@magic:~/project/MyGame$ cocos compile -p androID -m release
编译完后,会提示你输入keystore文件:
Move apk to /home/magic/project/MyGame/publish/androID
Please input the absolute/relative path of ".keystore" file:
输入刚才生成的demo.keystore完整路径,比如这里是/home/magic/project/MyGame/demo.keystore,然后会提示输入这个keystore的密码,alias以及alias的密码,然后脚本会自动做签名,生成做了签名的apk文件:
magic@magic:~/project/MyGame$ ls -l /home/magic/project/MyGame/publish/androID/MyGame-release-signed.apk
-rw-rw-r-- 1 magic magic 6145648 Jun 17 09:07 /home/magic/project/MyGame/publish/androID/MyGame-release-signed.apk 总结

以上是内存溢出为你收集整理的怎么将cocos2d-js 3.x 成功在android平台编译打包 (测试ok)全部内容,希望文章能够帮你解决怎么将cocos2d-js 3.x 成功在android平台编译打包 (测试ok)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1084826.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存