[COCOS2DX]COCOS命令新建项目+编译安卓项目并成功运行

全程搭建过程参考网址:

http://blog.csdn.net/lengxue789/article/details/38116475

http://blog.csdn.net/cbbbc/article/details/38098837

http://www.cnblogs.com/9420sunshine/p/3638740.html

其中有些dll、lib之类的是需要添加到指定的系统目录的,参考相关博文照做即可:

[4]_thumb[1]

1.利用cocos命令创建helloworld项目

cocos new HelloWorld -p com.cocos2dx.org -l cpp -d C:\ComputerScience\workspace-cocos

正常运行编译helloworld就出来了

2.搭建安卓环境

JDK环境变量:

配置jdk:

在JDK安装完毕之后,需要手动进行环境变量的配置

1)在系统变量里新建JAVA_HOME变量,变量值为:D:/Program Files/Java/jdk1.6.0_14(根据自己的安装路径填写)

2)新建classpath变量,变量值为:.;%JAVA_HOME%/lib;%JAVA_HOME%/lib/tools.jar (注意前面的. 不要忘记了)

3)在path变量(已存在不用新建)添加变量值:%JAVA_HOME%/bin;%JAVA_HOME%/jre/bin(注意变量值之间用“;”隔开)

4)重新注销系统并重新登陆后 “开始”-->“运行”-->输入“javac”-->"Enter",如果能正常打印用法说明配置成功!

一开始尝试利用安装Android Studio:

[5]_thumb[1]

出现以下错误,google了好久没解决:

Error:Execution failed for task ':helloWorld:compileDebugNdk'.

> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\ComputerScience\ndk\ndk-build.cmd'' finished with non-zero exit value 2

决定改用Eclipse来对安卓项目进行部署,在线更新adt的网址为http://dl-ssl.google.com/android/eclipse/

然后下载好sdk manager,先不在线更新,下载4.4.2离线包覆盖到api 19的文件夹里面,再后台更新。

3.配置ndk、ant等

将下载好的包都解压到ComputerScience文件夹

age_thumb[2]

进入到cocos2dx相关目录执行setup.py:

cd C:\ComputerScience\cocos2d-x-3.5

setup.py

ANT_ROOT:C:\ComputerScience\ant\bin

NDK_ROOT:C:\ComputerScience\ndk

SDK_ROOT:C:\Program Files (x86)\Android\android-sdk

安装好后重新执行setup.py确认以下变量都已经设置好了:

[6]_thumb[2]

4.部署Android项目到Eclipse

cmd执行以下命令

cd C:\ComputerScience\workspace-cocos\HelloWorld\proj.android

python build_native.py

然后修改local.properties

[7]_thumb[1]

添加下列项进去

ndk.dir=C:\\ComputerScience\\ndk

导入Helloworld项目,并在src目录中右键import进C:\ComputerScience\workspace-cocos\HelloWorld\cocos2d\cocos\platform\android\java(导入libcocos2dx):

[9]_thumb[2]

并进行如下修改:

[8]_thumb[1]

10]_thumb[1]

11]_thumb[2]

出现以下报错:

03:13:55 **** Incremental Build of configuration Release for project HelloWorld ****

python C:/ComputerScience/workspace-eclipse/HelloWorld/build_native.py -b release all

Running command: compile

Can't find config file .cocos-project.json in path C:\ComputerScience\workspace-eclipse

Please use cocos console instead.

Traceback (most recent call last):

  File "C:/ComputerScience/workspace-eclipse/HelloWorld/build_native.py", line 43, in <module>

    build(opts.build_mode)

  File "C:/ComputerScience/workspace-eclipse/HelloWorld/build_native.py", line 28, in build

    raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")

Exception: Build dynamic library for project [ C:\ComputerScience\workspace-eclipse\HelloWorld\../ ] fails!

参考http://rmarcejaeger.com/2015/03/24/tutorial-how-to-create-a-new-cocos-2d-x-game-project-using-windows/添加下面的json文件到helloworld的上级目录:

12]_thumb[1]

在Eclipse执行运行,apk成功生成:

13]_thumb[1]

在手机端运行截图如下:

clipboard

posted @ 2015-04-16 15:57  何解一直犯相同错误?  阅读(13448)  评论(0编辑  收藏  举报