2012-03-01 02:51:58 +08:00
#!/bin/bash
2011-03-23 09:42:23 +08:00
# check the args
2013-06-04 22:21:41 +08:00
# $1: root of cocos2dx $2: app path $3: pakcage path
2011-03-23 09:42:23 +08:00
2011-03-23 14:30:14 +08:00
COCOS2DX_ROOT = $1
2013-06-04 22:21:41 +08:00
APP_DIR = $2
PACKAGE_PATH = $3
USE_BOX2D = $4
USE_CHIPMUNK = $5
USE_LUA = $6
APP_NAME = ` basename ${ APP_DIR } `
2013-01-01 13:18:10 +08:00
HELLOWORLD_ROOT = $COCOS2DX_ROOT /samples/Cpp/HelloCpp
2012-05-25 08:12:48 +08:00
COCOSJAVALIB_ROOT = $COCOS2DX_ROOT /cocos2dx/platform/android/java
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
2013-06-04 22:21:41 +08:00
copy_cpp_h( ) {
2011-03-23 14:30:14 +08:00
mkdir $APP_DIR /Classes
2013-06-04 22:21:41 +08:00
cp $COCOS2DX_ROOT /template/android/Classes/* $APP_DIR /Classes
2011-03-23 09:42:23 +08:00
}
2011-03-23 14:30:14 +08:00
# copy resources
2013-06-04 22:21:41 +08:00
copy_resouces( ) {
2011-07-28 09:58:44 +08:00
mkdir $APP_DIR /Resources
2013-06-04 22:21:41 +08:00
cp -rf $HELLOWORLD_ROOT /Resources/iphone/* $APP_DIR /Resources
2011-03-23 09:42:23 +08:00
}
# from HelloWorld copy src and jni to APP_DIR
2013-06-04 22:21:41 +08:00
copy_src_and_jni( ) {
cp -rf $HELLOWORLD_ROOT /proj.android/{ jni,src} $APP_DIR /proj.android
2013-06-15 14:20:43 +08:00
2012-08-30 18:27:35 +08:00
# replace Android.mk
2013-06-04 22:21:41 +08:00
sh $COCOS2DX_ROOT /template/android/gamemk.sh $APP_DIR /proj.android/jni/Android.mk $USE_BOX2D $USE_CHIPMUNK $USE_LUA
2013-06-10 22:35:05 +08:00
2013-06-21 07:24:01 +08:00
if [ $USE_LUA = "true" ] ; then
2013-06-10 22:35:05 +08:00
# copy lua script
cp " $COCOS2DX_ROOT " /scripting/lua/script/* " $APP_DIR " /Resources
fi
2011-03-23 14:30:14 +08:00
}
# copy build_native.sh and replace something
2013-06-04 22:21:41 +08:00
copy_build_native( ) {
2011-03-23 14:30:14 +08:00
# here should use # instead of /, why??
2012-05-02 17:29:16 +08:00
sed " s#__cocos2dxroot__# $COCOS2DX_ROOT #;s#__ndkroot__# $NDK_ROOT #;s#__projectname__# $APP_NAME # " $COCOS2DX_ROOT /template/android/build_native.sh > $APP_DIR /proj.android/build_native.sh
chmod u+x $APP_DIR /proj.android/build_native.sh
2011-03-23 09:42:23 +08:00
}
2012-10-05 01:23:07 +08:00
# copy debugger script and replace templated parameters
2013-06-04 22:21:41 +08:00
copy_ndkgdb( ) {
2013-06-16 19:25:20 +08:00
sed " s#__projectname__# $APP_NAME #;s#__packagename__# $PACKAGE_PATH #;s#__androidsdk__# $ANDROID_SDK_ROOT #;s#__ndkroot__# $NDK_ROOT #;s#__cocos2dxroot__# $COCOS2DX_ROOT # " $COCOS2DX_ROOT /template/android/ndkgdb.sh > $APP_DIR /proj.android/ndkgdb.sh
2012-10-05 01:23:07 +08:00
chmod u+x $APP_DIR /proj.android/ndkgdb.sh
}
2012-08-30 18:27:35 +08:00
# copy .project and .classpath and replace project name
modify_project_classpath( ) {
sed " s/HelloCpp/ $APP_NAME / " $COCOS2DX_ROOT /template/android/.project > $APP_DIR /proj.android/.project
cp -f $COCOS2DX_ROOT /template/android/.classpath $APP_DIR /proj.android
}
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( ) {
2012-07-23 14:56:40 +08:00
sed " s/HelloCpp/ $APP_NAME /;s/org\.cocos2dx\.hellocpp/ $PACKAGE_PATH / " $HELLOWORLD_ROOT /proj.android/AndroidManifest.xml > $APP_DIR /proj.android/AndroidManifest.xml
2011-03-23 09:42:23 +08:00
}
2012-07-23 14:56:40 +08:00
# modify HelloCpp.java
2013-06-04 22:21:41 +08:00
modify_applicationdemo( ) {
2011-05-20 16:59:19 +08:00
convert_package_path_to_dir $PACKAGE_PATH
2012-07-23 14:56:40 +08:00
# rename APP_DIR/android/src/org/cocos2dx/hellocpp/HelloCpp.java to
# APP_DIR/android/src/org/cocos2dx/hellocpp/$APP_NAME.java, change hellocpp to game
sed " s/HelloCpp/ $APP_NAME /;s/org\.cocos2dx\.hellocpp/ $PACKAGE_PATH /;s/hellocpp/game/ " $APP_DIR /proj.android/src/org/cocos2dx/hellocpp/HelloCpp.java > $APP_DIR /proj.android/src/$PACKAGE_PATH_DIR /$APP_NAME .java
rm -fr $APP_DIR /proj.android/src/org/cocos2dx/hellocpp
2011-05-09 15:21:08 +08:00
}
2013-06-04 22:21:41 +08:00
modify_layout( ) {
2012-05-02 17:29:16 +08:00
rm -f $APP_DIR /proj.android/res/layout/main.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
2013-06-04 22:21:41 +08:00
copy_icon( ) {
2012-05-02 17:29:16 +08:00
if [ ! -d $APP_DIR /proj.android/res/drawable-hdpi ] ; then
cp -r $HELLOWORLD_ROOT /proj.android/res/drawable-hdpi $APP_DIR /proj.android/res
cp -r $HELLOWORLD_ROOT /proj.android/res/drawable-ldpi $APP_DIR /proj.android/res
cp -r $HELLOWORLD_ROOT /proj.android/res/drawable-mdpi $APP_DIR /proj.android/res
2011-11-30 15:30:11 +08:00
fi
}
2012-08-21 16:45:23 +08:00
copy_cpp_h
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
2012-10-05 01:23:07 +08:00
copy_ndkgdb
2013-03-20 20:54:31 +08:00
#modify_project_classpath
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