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.

We used and modified an existing cocos2d-x script, found in the jni folder under the filename 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:

./ ../../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/
However, it required a slight modification after we created our own static function libraries.
The original was modified as follows:


append_str=' \'

    for file in /*
if [ ! -f $file/ ]; then
        if [ -f $file ]; then
            echo $file$append_str | grep .cpp

        if [ -d $file ]; then
            list_alldir $file

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

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

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).



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" &
   echo "ERROR"


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

No Comments

Leave a comment