用于android cocos2dx 开发使用的若干脚本

来源:互联网 发布:仓库记账软件 编辑:程序博客网 时间:2024/05/29 13:36
1、x.sh 就是把当前进程x掉的脚本,因为调试的时候难免有很多重启应用的过程,将这部分写成脚本,就省得每次去点back,当然,主要是为下边两个脚本使用

x.sh就是简单的用adb devices看有多少个设备连上,再每个设备ps|grep一下,再kill -9。对于有些机器(比如moto的坑爹机,虽然root但是adb shell进去默认是shell组的,可能会遇到权限问题。这个处理起来比较复杂,就不说拉)

#!/bin/shtarget_ps="com.kevin.test"tmpname="tmp"tmpfile=${PWD}/tmpnameawk 'BEGIN{  while("adb devices" |getline info)  {    split(info,devinfo);    if( devinfo[1] != "List" && devinfo[1] != "" )    {      print devinfo[1];    }  }}'>${tmpfile}cat ${tmpfile} | while read devnamedo echo "Kill device: " $devname " process" adb -s $devname shell kill -9 `adb -s $devname shell ps|grep ${target_ps} |awk '{ print $2 }'`donerm ${tmpfile}#kill iphone simulator instance#killall webgame
echo "Killed ${target_ps} process."

2._install.sh

对于cocos2dx for android,它提供了一个build_native.sh 用来调用ndk编译。不过对于我们来说还是不够方便,因为我们编译完必须切到eclipse里头,refresh一下,再重新打包,上传,安装。于是_intall.sh就是一步到位。基本过程就是:调用x.sh x掉上一个进程,调用build_native.sh编译,调用ant打包,最后用am start启动


#!/bin/shapp_name=HelloWordpkg=com.kevin.testapp_root=${PWD}$app_root/x.sh$app_root/build_native.sh/usr/bin/ant -file $app_root/build.xml debug installif [ -n "$android_platform_tool" ]; then  android_platform_tool=$android_platform_tool/fi${android_platform_tool}adb shell am start -n $pkg/$pkg.$app_name

注意,_install.sh必须放在项目根目录下,因为ant要读build.xml

另外,pkg就是包名,app_name就是要启动的activity名


3.install.sh

没有了开头的下杠。为什么要多弄一个install.sh呢?因为我们发现,每次编译,打包,上传,安装,太耗时间了,项目一大,这个过程没几分钟都做不完,这样效率很低。而且由于增量编译,我们发现,时间并不是耗在编译上的,主要是打包,上传,安装这类涉及到sd卡读写的操作慢。

cocos2dx是c++方式的cocos2d引擎,对于android来说,最终会生成libgame.so 之类的动态库给虚拟机调用。也就是说,如果改动是发生在c++代码上的,那么我们只要把动态库替换掉,不需要重新打包上传整个项目就可以了。我们能看到,apk安装后会把库copy到/data/data/包名/libs下。于是install.sh主要就是不调用ant,而是把编译后的动态库替换掉,再重启,跟_install.sh差不多:


#!/bin/shapp_name=HelloWorldpkg=com.kevin.testapp_root=${PWD}$app_root/x.sh$app_root/build_native.shadb push $app_root/libs/armeabi/libgame.so /data/data/$pkg/lib/libgame.soecho "adb push $app_root/libs/armeabi/libgame.so /data/data/$pkg/lib/libgame.so"if [ -n "$android_platform_tool" ]; then  android_platform_tool=$android_platform_tool/fi${android_platform_tool}adb shell am start -n $pkg/$pkg.$app_name


呵呵,代码改动后更新从需要2,3分钟一下子变成不到10秒

注:需要在环境变量中配置 

android_platform_tool

为android的工具文件夹(即adb所在位置)


原创粉丝点击