Cocos2d-x 3.0游戏开发之android交叉编译

满堂花醉三千客,一剑霜寒十四州。这篇文章主要讲述Cocos2d-x 3.0游戏开发之android交叉编译相关的知识,希望能为你提供帮助。
作者:Senlern
转载请注明,原文链接:http://blog.csdn.net/zhang429350061/article/details/37959489

在上一篇文章我分享了如在win32下配置环境搭建project。没有看的童鞋请先看下这篇文章

Cocos2d-x 3.0游戏开发之android交叉编译

文章图片
:http://blog.csdn.net/zhang429350061/article/details/37958275


-----------------------------------------下载JDK配置环境变量---------------------------------
下载网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
成功安装之后须要配置系统环境变量:
新建变量:CLASSPATH       值 为:.
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


新建变量:java_HOME   值 为:JDK的实际安装路径
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


在path中新增加%JAVA_HOME%\bin; (注意最后的分号)
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片





------------------------------下载NDK配置环境变量---------------------------
下载地址:http://developer.android.com/tools/sdk/ndk/index.html
下载完毕之后是个压缩包。解压就可以。

新建变量:NDK_ROOT   值 为:你解压的路径附近进去就好了 
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片



---------------------------開始命令行编译androidproject------------------------
首先在cmd中先cd到你project的E:\MyGame\proj.android中,然后直接执行build_native.py脚本
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


我们看到以下输出了Select NDK toolchain version was 4.8 !太棒了!
接下来就是漫长的编译过程了
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片

接着会有例如以下的输出:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


编译完毕之后是这个样子的:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


恭喜!大功告成
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片

--------------------------------------project导入Eclipse,在自己android手机上跑起来---------------------------------------
我们直接使用一个整合的ADT,里面有eclipse和android的SDK。下载地址:http://developer.android.com/sdk/index.html
下载解压之后我们打开eclipse目录里面的eclipse.exe启动Eclipse。
启动之后点击File-> New-> Project:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


然后选择Android Project From Existing Code:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


然后在Root Directory中选择你project的proj.android文件夹,点击Finish
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片




等等,是不是project名字处有一个红色的叉号,貌似 是有错误,怎么办呐??
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片
哈哈,这么办:
项目project处右键,选择Import:
Cocos2d-x 3.0游戏开发之android交叉编译

然后选择下图显示的选择项:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


然后在Root Directory中选择例如以下路径(自己參考自己的路径设置):
注意:以下的Project中仅仅选择第一个就能够,其他的不选,你能够先在右側的button中选择Deselect All,然后在单独选择第一个。然后Finish
Cocos2d-x 3.0游戏开发之android交叉编译

是不是错误没有了,就是这么奇妙Cocos2d-x 3.0游戏开发之android交叉编译

文章图片



如今我们就能够跑在自己的android手机上了。在project处右键选择例如以下图:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


然后会弹出一个选择手机的框框,双击就可以:
Cocos2d-x 3.0游戏开发之android交叉编译

此时我们能够看到Console以下的输出:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


是不是如今你的游戏已经在你的手机上跑起来了???!!
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片

最后再给大家透露一个小知识,假设你想在logcat中仅仅查看cocos2d-x的debug输出,你能够点击这个绿色的加号:
Cocos2d-x 3.0游戏开发之android交叉编译

然后这么设置:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


然后就是酱紫:
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片

Cocos2d-x 3.0游戏开发之android交叉编译

文章图片


OK!是不是这样查看debug信息方便多了。
----------------------------------------备注------------------------------------
【Cocos2d-x 3.0游戏开发之android交叉编译】能力有限。欢迎交流。如有指正,不胜感激!(大家帮忙顶一下
Cocos2d-x 3.0游戏开发之android交叉编译

文章图片



























    推荐阅读