ubuntu下不用eclipse开发cocos2d-x(命令行)
之前在ubuntu下通过eclipse搭建开发cocos2d-x的环境,但是由于eclipse界面在ubuntu显得很丑,在里面写代码,完全没有感觉,后来我转到了win7上通过vs2010和eclipse共同开发cocos2dx的安卓项目,虽然成功了,但是eclipse是个吃软饭的角色,只负责编译一下,然后联机调试。网上也有人说可以搭建一下eclipse c++ 环境,但感觉很烦所。所以今天又回到ubuntu下搭建了一个不用eclipse的环境。
1.首先我们用 cocos2d-x-2.1.4/tools/project-creator/create_project.py 创建各个平台的工程。
create_project.py -project PROJECT_NAME -package PACKAGE_NAME -language PROGRAMING_LANGUAGE
参考
charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/tools/project-creator$ python create_project.py -project HelloCxue -package org.cocos2dx.cxue -language cpp proj.ios : Done! proj.android : Done! proj.win32 : Done! proj.mac : Done! proj.blackberry : Done! proj.linux : Done! proj.marmalade : Done! New project has been created in this path: /home/charlesxue/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue Have Fun!
2.这时会在cocos2d-x根目录下生成project文件夹,文件夹下有我们刚才创建的工程
charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects$ ls HelloCxue HelloWorld charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects$ cd HelloCxue/ charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue$ ls Classes proj.android proj.blackberry proj.ios proj.linux proj.mac proj.marmalade proj.win32 Resources
在工程下Classes 和 Resource 是各个平台的共有文件夹,所以我们可以在linux平台下开发把要添加的.h .cpp文件放到Classes文件夹下,想要生成安卓的程序,直接到proj.android编译即可。
3.更改Resources/font ,去掉之间的空格防止在安卓编译的时候出错。
4.在linux上编译工程,进行测试。
charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.linux/bin$ ls debug charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.linux/bin$ cd debug/ charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.linux/bin/debug$ ls HelloCxue charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.linux/bin/debug$ ./HelloCxue cocos2d-x debug info [Ready for GLSL] cocos2d-x debug info [Ready for OpenGL 2.0] cocos2d-x debug info [ <dict> cocos2d.x.version: 2.1rc0-x-2.1.4 cocos2d.x.compiled_with_profiler: false cocos2d.x.compiled_with_gl_state_cache: true gl.vendor: X.Org gl.renderer: Gallium 0.4 on AMD RV710 gl.version: 2.1 Mesa 9.0 gl.max_texture_size: 8192 gl.max_texture_units: 32 gl.supports_PVRTC: false gl.supports_NPOT: true gl.supports_BGRA8888: false gl.supports_discard_framebuffer: false gl.supports_vertex_array_object: true </dict>]
如图:
5.编译安卓依赖的c++库
./build_native.sh
charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.android$ ls AndroidManifest.xml build_native.sh jni project.properties res ant.properties build.xml proguard-project.txt README.md src charlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.android$ ./build_native.sh NDK_ROOT = /home/charlesxue/setup/android_develop/android-ndk-r8e COCOS2DX_ROOT = /home/charlesxue/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.android/../../.. APP_ROOT = /home/charlesxue/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.android/.. APP_ANDROID_ROOT = /home/charlesxue/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.android Using prebuilt externals make: Entering directory `/home/charlesxue/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.android' Compile++ thumb : cocos2dcpp_shared <= main.cpp
6. 修改proj.android 下的project.properties 如下 根据自己情况修改 添加sdk.dir
如下:
11 target=android-18 12 sdk.dir=/home/charlesxue/setup/android_develop/adt-bundle-linux-x86-20130729/sdk 13 android.library.reference.1=../../../cocos2dx/platform/android/java
7.安装 ant 。Apache Ant,是一个将软件编译、测试、部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发。由Apache软件基金会所提供。
sudo apt-get install ant
8.执行
ant debug
9.编译成功后我们会发现 bin目路下多了很多文件。
rlesxue@THSHIBA:~/setup/cocos2d-x/cocos2d-x-2.1.4/projects/HelloCxue/proj.android/bin$ ls AndroidManifest.xml classes dexedLibs HelloCxue-debug.apk proguard.txt AndroidManifest.xml.d classes.dex HelloCxue.ap_ HelloCxue-debug-unaligned.apk res build.prop classes.dex.d HelloCxue.ap_.d HelloCxue-debug-unaligned.apk.d R.txt
10.把 helloCxue-debug.apk 装载到手机。
adb install HelloCxue-debug