Cocos2d-x 3.0 开发 使用Cocos2d-x 3.0rc,一条命令打包Android
2014-04-17 16:37
696 查看
1、目录改动
每个版本都会有目录变动,这次的版本也不例外。最显眼的就是,在文件的根目录中增加了一个名为setup.py的配置文件。运行它可以配置系统的一些环境变量。2、创建项目
新的版本我们来动手创建一个新项目吧。找到tools文件夹....额 打包的那个名为create-project.py的文件似乎木有了!原来,在新版本中,创建新项目已经可以通过命令行来创建了,相对于先前版本的图形界面,命令行更简洁。我们要在setup.py中设置参数。以mac平台为例,我们进入到对应目录,运行脚本setup.py:Setting up cocos2d-x... -> Adding COCOS2D_CONSOLE_ROOT environment variable... OK -> Added: COCOS_CONSOLE_ROOT = /Users/fansy/Documents/cocos2d-x-3.0rc0/tools/cocos2d-console/bin -> Looking for NDK_ROOT envrironment variable... FOUND -> Looking for ANDROID_SDK_ROOT envrironment variable... NOT FOUND Please enter its path (or press Enter to skip): /Users/fansy/lib/android-sdk-macosx ADDED -> Added: ANDROID_SDK_ROOT = /Users/fansy/lib/android-sdk-macosx -> Looking for ANT_ROOT envrironment variable... NOT FOUND Please enter its path (or press Enter to skip): /Users/fansy/Documents/ant-1.9.3/bin ADDED -> Added: ANT_ROOT = /Users/fansy/Documents/ant-1.9.3/bin Set up successfull: ANT_ROOT was added into /Users/fansy/.bash_profile Please execute command: "source /Users/fansy/.bash_profile" to make added system variables take effect
显然,我们在这里设置了cocos2dx命令行的路径,android_sdk的路径,ant_root的路径。这些路径都是打Android包需要使用的。接下来我们运行:
source ~/.bash_profile
这样就可以将变量配置到bash_profile中。接下来我们就可以创建项目了,这里使用了一个cocos new命令,有点像c++的分配一块内存 哈 触控的程序员兄弟挺幽默呢。
localhost:~ fansy$ cocos new Runing command: new usage: cocos new [-h] [-p PACKAGE_NAME] -l {cpp,lua,js} [-d DIRECTORY] [-t TEMPLATE_NAME] [--no-native] [PROJECT_NAME] cocos new: error: argument -l/--language is required localhost:~ fansy$ cocos new HelloNew2dx -p com.fansy.hello -l cpp -d ~/Documents/Code/ Runing command: new > Copy template into /Users/fansy/Documents/Code/HelloNew2dx > Copying cocos2d-x files... > Rename project name from 'HelloCpp' to 'HelloNew2dx' > Replace the project name from 'HelloCpp' to 'HelloNew2dx' > Replace the project package name from 'org.cocos2dx.hellocpp' to 'com.fansy.hello'
这样我们的项目就创建好了。
3、打包运行
进入项目目录,我们可以直接运行"cocos run"命令行,在各平台上运行。localhost:~ fansy$ cd ~/Documents/Code/HelloNew2dx/ localhost:HelloNew2dx fansy$ cocos run Runing command: compile The target platform is not specified. You can specify a target platform with "-p" or "--platform". Available platforms : win32, android, ios, mac, linux localhost:HelloNew2dx fansy$ cocos run -p ios
命令通过“-p”来设置平台,设置成ios的话,在一段编译的信息后,会自动打开模拟器。
......blablabla...... ** BUILD SUCCEEDED ** build succeeded. Runing command: deploy Deploying mode: debug Runing command: run starting application running: '/Users/fansy/Documents/cocos2d-x-3.0rc0/tools/cocos2d-console/bin/../plugins/project_run/bin/ios-sim launch /Users/fansy/Documents/Code/HelloNew2dx/bin/debug/ios/HelloNew2dx.app &' localhost:HelloNew2dx fansy$ 2014-03-15 19:08:35.432 HelloNew2dx iOS[1522:80b] cocos2d: surface size: 960x640 cocos2d: { cocos2d.x.version: 3.0-rc0 cocos2d.x.compiled_with_gl_state_cache: true cocos2d.x.build_type: DEBUG gl.supports_vertex_array_object: true cocos2d.x.compiled_with_profiler: false gl.renderer: Apple Software Renderer gl.vendor: Apple Computer, Inc. gl.max_texture_size: 4096 gl.max_samples_allowed: 4 gl.version: OpenGL ES 2.0 APPLE-9.2.1 gl.supports_S3TC: false gl.supports_ATITC: false gl.supports_ETC1: false gl.max_texture_units: 8 gl.supports_PVRTC: true gl.supports_NPOT: true gl.supports_discard_framebuffer: true gl.supports_BGRA8888: false } libpng warning: iCCP: known incorrect sRGB profile
然后就是我们熟悉的日志了。
接下来测试Android打包。同样运行“cocos run”。会打出debug的apk,并自动连接到设备上。
localhost:HelloNew2dx fansy$ cocos run -p android -j 4 Runing command: compile Building mode: debug building native The Selected NDK toolchain version was 4.7 ! ......blablabla.......... BUILD SUCCESSFUL Total time: 4 seconds Move apk to /Users/fansy/Documents/Code/HelloNew2dx/bin/debug/android build succeeded. Runing command: deploy Deploying mode: debug installing on device running: '/Users/fansy/lib/android-sdk-macosx/platform-tools/adb uninstall com.fansy.hello' - waiting for device -
这时我们打开android模拟器,或连接真机,即可安装运行我们的apk了。
本篇博客出自阿修罗道,转载请注明出处,禁止用于商业用途:/article/1383415.html
相关文章推荐
- 实习小白::(转) Cocos2d-x 3.0 开发(十七)使用Cocos2d-x 3.0rc,一条命令打包Android
- Cocos2d-x 3.0 开发(十七)使用Cocos2d-x 3.0rc,一条命令打包Android
- Cocos2d-x 3.0 开发(十七)使用Cocos2d-x 3.0rc,一条命令打包Android
- Cocos2d-x 3.0 开发(十七)使用Cocos2d-x 3.0rc,一条命令打包Android
- cocos2d-x 3.0开发笔记---vector的使用
- Android使用Gradle命令动态传参完成打包不需要修改代码
- 实习小白::(转)Cocos2d-x 3.0开发(六)使用cocoStudio创建一个骨骼动画
- Android开发之ADB命令使用技巧
- Cocos2d-x 3.0开发(二)使用自动脚本创建cocos2d-x 3.0项目
- 一、cocos2d-x 3.0 final使用httpclient编译到android,需要用到的android.mk
- cocos2d-x 3.0rc开发指南:Windows下Android环境搭建
- Cocos2d-x 3.0 开发(十四)使用UIScrollView 实现大小不同物品拖动展示
- Cocos2d-x 3.0开发(六)使用cocoStudio创建一个骨骼动画
- cocos2d-x 3.0rc开发指南:Windows下Android环境搭建
- Android开发中使用adb shell命令出现sqlite3 : not found 问题
- Cocos2d-x 3.0开发(六)使用cocoStudio创建一个骨骼动画
- Cocos2d-x 3.0 开发(四)使用CocoStudio创建UI并载入到程序中
- Cocos2d-x 3.0开发(二)使用自动脚本创建cocos2d-x 3.0项目
- Cocos2d-x 3.0开发(六)使用cocoStudio创建一个骨骼动画
- android stutio创建证书与打包APP上线、配制gradle中的证书,使用第三方平台SDK方便开发调试