2012-03-01 02:51:58 +08:00
#!/bin/bash
2011-03-23 09:42:23 +08:00
# check the args
2011-05-20 16:59:19 +08:00
# $1: root of cocos2dx $2: app name $3: ndk root $4:pakcage path
2011-03-23 09:42:23 +08:00
APP_NAME = $2
2011-03-23 14:30:14 +08:00
COCOS2DX_ROOT = $1
APP_DIR = $COCOS2DX_ROOT /$APP_NAME
HELLOWORLD_ROOT = $COCOS2DX_ROOT /HelloWorld
NDK_ROOT = $3
2011-05-20 16:59:19 +08:00
PACKAGE_PATH = $4
2012-02-29 17:48:45 +08:00
NEED_BOX2D = $5
NEED_CHIPMUNK = $6
NEED_LUA = $7
2011-05-20 16:59:19 +08:00
# xxx.yyy.zzz -> xxx/yyy/zzz
convert_package_path_to_dir( ) {
PACKAGE_PATH_DIR = ` echo $1 | sed -e "s/\./\//g" `
}
2011-03-23 09:42:23 +08:00
# make director andorid and copy all files and directories into it
move_files_into_android( ) {
mkdir $APP_DIR /android
for file in $APP_DIR /*
do
if [ -d $file ] ; then
if [ $file != $APP_DIR /android ] ; then
mv -f $file $APP_DIR /android
fi
fi
if [ -f $file ] ; then
mv $file $APP_DIR /android
fi
done
}
copy_cpp_h_from_helloworld( ) {
2011-03-23 14:30:14 +08:00
mkdir $APP_DIR /Classes
2012-01-10 17:05:42 +08:00
for file in ` ls $HELLOWORLD_ROOT /Classes/* | grep -E '.*\.(cpp|h|mk)' `
2011-03-23 09:42:23 +08:00
do
if [ -f $file ] ; then
2011-03-23 14:30:14 +08:00
cp $file $APP_DIR /Classes
2011-03-23 09:42:23 +08:00
fi
done
}
2011-03-23 14:30:14 +08:00
# copy resources
copy_resouces( ) {
2011-07-28 09:58:44 +08:00
mkdir $APP_DIR /Resources
2011-03-23 09:42:23 +08:00
2012-02-25 10:14:06 +08:00
for file in $HELLOWORLD_ROOT /Resources/*
2011-03-23 09:42:23 +08:00
do
2012-03-01 16:57:59 +08:00
cp -rf $file $APP_DIR /Resources
2011-03-23 09:42:23 +08:00
done
}
# from HelloWorld copy src and jni to APP_DIR
copy_src_and_jni( ) {
cp -rf $HELLOWORLD_ROOT /android/jni $APP_DIR /android
cp -rf $HELLOWORLD_ROOT /android/src $APP_DIR /android
2011-03-23 14:30:14 +08:00
# repalce Android.mk and Application.mk
2012-02-29 17:48:45 +08:00
sh $COCOS2DX_ROOT /template/android/classesmk.sh $APP_DIR /Classes/Android.mk $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
sh $COCOS2DX_ROOT /template/android/gamestaticmk.sh $APP_DIR /android/jni/Android.mk $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
sh $COCOS2DX_ROOT /template/android/gamemk.sh $APP_DIR /android/jni/helloworld/Android.mk $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
sh $COCOS2DX_ROOT /template/android/application.sh $APP_DIR /android/jni/Application.mk $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
2011-03-23 14:30:14 +08:00
}
# copy build_native.sh and replace something
copy_build_native( ) {
# here should use # instead of /, why??
sed " s#__cocos2dxroot__# $COCOS2DX_ROOT #;s#__ndkroot__# $NDK_ROOT #;s#__projectname__# $APP_NAME # " $COCOS2DX_ROOT /template/android/build_native.sh > $APP_DIR /android/build_native.sh
2011-08-04 19:23:12 +08:00
chmod u+x $APP_DIR /android/build_native.sh
2011-03-23 09:42:23 +08:00
}
# replace AndroidManifext.xml and change the activity name
# use sed to replace the specified line
modify_androidmanifest( ) {
2011-05-20 17:43:29 +08:00
sed " s/ApplicationDemo/ $APP_NAME /;s/org\.cocos2dx\.application/ $PACKAGE_PATH / " $HELLOWORLD_ROOT /android/AndroidManifest.xml > $APP_DIR /android/AndroidManifest.xml
2011-03-23 09:42:23 +08:00
}
2011-05-09 15:21:08 +08:00
# modify ApplicationDemo.java
2011-03-23 09:42:23 +08:00
modify_applicationdemo( ) {
2011-05-20 16:59:19 +08:00
convert_package_path_to_dir $PACKAGE_PATH
2011-05-09 15:21:08 +08:00
# rename APP_DIR/android/src/org/cocos2dx/application/ApplicationDemo.java to
# APP_DIR/android/src/org/cocos2dx/application/$APP_NAME.java, change helloworld to game
2012-02-29 17:48:45 +08:00
sed " s/ApplicationDemo/ $APP_NAME /;s/helloworld/game/;s/org\.cocos2dx\.application/ $PACKAGE_PATH / " $APP_DIR /android/src/org/cocos2dx/application/ApplicationDemo.java > $APP_DIR /android/src/$PACKAGE_PATH_DIR /$APP_NAME .java
2011-05-20 16:59:19 +08:00
rm -fr $APP_DIR /android/src/org/cocos2dx/application
2011-05-09 15:21:08 +08:00
2012-02-29 17:48:45 +08:00
# load need .so
CONTENT =
2012-03-01 02:51:58 +08:00
if [ $NEED_BOX2D = "true" ] ; then
CONTENT = $CONTENT 'System.loadLibrary("box2d");'
2012-02-29 17:48:45 +08:00
fi
2012-03-01 02:51:58 +08:00
if [ $NEED_CHIPMUNK = "true" ] ; then
CONTENT = $CONTENT 'System.loadLibrary("chipmunk");'
2012-02-29 17:48:45 +08:00
fi
2012-03-01 02:51:58 +08:00
if [ $NEED_LUA = "true" ] ; then
CONTENT = $CONTENT 'System.loadLibrary("lua");'
2012-02-29 17:48:45 +08:00
fi
2011-05-09 15:21:08 +08:00
2012-03-01 16:57:59 +08:00
sed -i -e " s/System.loadLibrary(\"cocosdenshion\")\;/System.loadLibrary(\"cocosdenshion\")\; $CONTENT / " $APP_DIR /android/src/$PACKAGE_PATH_DIR /$APP_NAME .java
2011-05-09 15:21:08 +08:00
}
modify_layout( ) {
cp $HELLOWORLD_ROOT /android/res/layout/helloworld_demo.xml $APP_DIR /android/res/layout
sed "s/helloworld_gl_surfaceview/game_gl_surfaceview/" $APP_DIR /android/res/layout/helloworld_demo.xml > $APP_DIR /android/res/layout/game_demo.xml
rm -f $APP_DIR /android/res/layout/main.xml
rm -f $APP_DIR /android/res/layout/helloworld_demo.xml
2011-03-23 09:42:23 +08:00
}
2011-11-30 15:30:11 +08:00
# android.bat of android 4.0 don't create res/drawable-hdpi res/drawable-ldpi and res/drawable-mdpi.
# These work are done in ADT
copy_icon( ) {
if [ ! -d $APP_DIR /android/res/drawable-hdpi ] ; then
cp -r $HELLOWORLD_ROOT /android/res/drawable-hdpi $APP_DIR /android/res
cp -r $HELLOWORLD_ROOT /android/res/drawable-ldpi $APP_DIR /android/res
cp -r $HELLOWORLD_ROOT /android/res/drawable-mdpi $APP_DIR /android/res
fi
}
2011-05-20 16:59:19 +08:00
2011-03-23 09:42:23 +08:00
move_files_into_android
copy_cpp_h_from_helloworld
2011-03-23 14:30:14 +08:00
copy_resouces
2011-03-23 09:42:23 +08:00
copy_src_and_jni
2011-03-23 14:30:14 +08:00
copy_build_native
2011-03-23 09:42:23 +08:00
modify_androidmanifest
modify_applicationdemo
2011-05-09 15:21:08 +08:00
modify_layout
2011-11-30 15:30:11 +08:00
copy_icon