Useful scripts for developing Android games using cocos2d-x

Posted by | No Tags | Company life | No Comments on Useful scripts for developing Android games using cocos2d-x

In this post we would like to share two useful scripts. The first one dynamically include the files to be compiled; the second one installs and runs the app on all running emulators simultaneously, saving us precious time.

list.sh

We used and modified an existing cocos2d-x script, found in the jni folder under the filename list.sh. When running this script from command line in its original form with a folder name as parameter, it recursively goes through that folder (to indefinite depth) and outputs all files with “.cpp” extension.
For instance, typing in:


./list.sh ../../Classes

gives the following results:


../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \

That was the script we used to automatically include the necessary file paths in the “LOCAL_SRC_FILES” variable of jni/Android.mk.
However, it required a slight modification after we created our own static function libraries.
The original list.sh was modified as follows:


#!/bin/bash

append_str=' \'

list_alldir()
{
    for file in /*
    do
if [ ! -f $file/Android.mk ]; then
        if [ -f $file ]; then
            echo $file$append_str | grep .cpp
        fi

        if [ -d $file ]; then
            list_alldir $file
        fi
fi
    done
}

if [ $# -gt 0 ]; then
    list_alldir ""
else
    list_alldir "."
fi

This way, it also included all files with “.c” extension and, more importantly, excluded the folders containing “Android.mk”, since these folders were likely to contain the source of the static function libraries.

runOnAllEmulators.sh

This script installs and runs the compiled app on all running android emulators (and, with a minimal modification, on all connected devices) simultaneously. The script itself is fairly simple: it queries the names of all running emulators, and then installs and starts the required app on each of them. It requires only one parameter, that is the name of the application (it does not distinguish between small letters and capital letters).


#!/bin/sh

PWD=`pwd`

APP_DIR=`ls |grep -i ""`
APP_NAME=`ls $APP_DIR/bin |grep -i ""|awk -F"." '{print }'`

cd $APP_DIR/src

PACKAGE="`find -iname "$APP_NAME" -type d|tr -d "."|tr "/" "."|cut -c 2-`"

cd $PWD

if [ -n "$APP_DIR" ] && [ -n "$APP_NAME" ] && [ -n "$PACKAGE" ]; then

   DEVICES=$(adb devices | egrep "emulator"| egrep "(device)$"| awk '{print }';)

   for d in $DEVICES; do
      echo "INSTALL to $d"
      adb -s $d install -r $APP_DIR/bin/$APP_NAME.apk>/dev/null && adb -s $d shell am start -n $PACKAGE/.$APP_NAME && echo "$d COMPLETED" &
   done
else
   echo "ERROR"
fi

exit

Use the above scripts freely, and if you find any errors, just let us know. Any comments are welcome.


No Comments

Leave a comment