2012-03-01 02:51:58 +08:00
#!/bin/bash
2013-06-04 22:21:41 +08:00
# parameters passed to script
2011-03-24 09:37:56 +08:00
# This script should be called by create-android-project.bat
2013-06-04 22:21:41 +08:00
# or should be runned in linux shell. It can not be runned under cygwin.
2011-03-24 09:37:56 +08:00
# Don't modify the script until you know what you do.
2013-06-04 22:21:41 +08:00
PARAMS = $@
2013-06-04 22:25:07 +08:00
# you can set the environment here and uncomment them if you haven't set them in .bashrc
#export NDK_ROOT=
#export ANDROID_SDK_ROOT=
#export COCOS2DX_ROOT=
2011-03-24 09:37:56 +08:00
2011-04-26 14:51:17 +08:00
# set environment paramters
2013-06-04 22:21:41 +08:00
if [ " x ${ NDK_ROOT } " = = "x" ] ; then
NDK_ROOT = "/opt/android-ndk"
fi
2011-12-20 16:50:39 +08:00
2013-06-04 22:21:41 +08:00
if [ " x ${ ANDROID_SDK_ROOT } " = = "x" ] ; then
ANDROID_SDK_ROOT = "/opt/android-sdk-update-manager"
fi
ANDROID_CMD = " ${ ANDROID_SDK_ROOT } /tools/android "
2012-02-29 17:48:45 +08:00
2013-06-04 22:21:41 +08:00
if [ " x ${ COCOS2DX_ROOT } " = = "x" ] ; then
COCOS2DX_ROOT = " ${ HOME } /cocos2d-x "
if [ ! -d $COCOS2DX_ROOT ] ; then
COCOS2DX_ROOT = ` pwd `
fi
2011-12-20 16:50:39 +08:00
fi
2013-06-04 22:21:41 +08:00
if [ ! -d ${ NDK_ROOT } -o ! -d ${ ANDROID_SDK_ROOT } -o ! -x ${ ANDROID_CMD } ] ; then
echo "Please set the environment at first"
2011-12-20 16:50:39 +08:00
fi
2011-04-26 14:51:17 +08:00
2013-06-04 22:21:41 +08:00
USE_BOX2D = false
USE_CHIPMUNK = false
USE_LUA = false
2012-02-29 17:48:45 +08:00
print_usage( ) {
2013-06-04 22:21:41 +08:00
echo "usage:"
echo " $0 [-b|--box2d] [-c|--chipmunk] [-l|--lua] "
2012-02-29 17:48:45 +08:00
}
check_param( ) {
for param in ${ PARAMS [@] }
do
case $param in
-b | --box2d)
echo using box2d
2013-06-04 22:21:41 +08:00
USE_BOX2D = true
2012-02-29 17:48:45 +08:00
; ;
-c | --chipmunk)
echo using chipmunk
2013-06-04 22:21:41 +08:00
USE_CHIPMUNK = true
2012-02-29 17:48:45 +08:00
; ;
-l | --lua)
echo using lua
2013-06-04 22:21:41 +08:00
USE_LUA = true
2012-02-29 17:48:45 +08:00
; ;
-linux)
// skip it
; ;
*)
print_usage
exit 1
esac
done
2013-06-04 22:21:41 +08:00
if [ $USE_BOX2D = = "true" -a $USE_CHIPMUNK = = "true" ] ; then
echo '[WARN] Using box2d and chipmunk together!'
2012-02-29 17:48:45 +08:00
fi
}
2011-03-24 09:37:56 +08:00
# check if it was called by .bat file
2013-06-04 22:21:41 +08:00
if [ $# -ge 5 -a " x $5 " = = "xwindows" ] ; then
# should be called by .bat file
length = ` expr $# - 5`
PARAMS = ${ @ : 6 : $length }
check_param
2013-06-16 19:25:20 +08:00
ANDROID_SDK_ROOT = $ANDROID_SDK_ROOT COCOS2DX_ROOT = $COCOS2DX_ROOT sh $COCOS2DX_ROOT /template/android/copy_files.sh $1 $2 $3 $4 $USE_BOX2D $USE_CHIPMUNK $USE_LUA
2013-06-04 22:21:41 +08:00
exit
2011-03-24 09:37:56 +08:00
fi
# the bash file should not be called by cygwin
2011-08-05 10:07:14 +08:00
KERNEL_NAME = ` uname -s | grep "CYGWIN*" `
2013-06-04 22:21:41 +08:00
if [ " x $KERNEL_NAME " != "x" ] ; then
echo "[ERROR] Don't run in cygwin. You should run .bat file"
2011-11-18 20:35:35 +08:00
exit
2011-03-24 09:37:56 +08:00
fi
# ok, it was run under linux
create_android_project( ) {
2013-06-04 22:21:41 +08:00
DEFAULT_PACKAGE_PATH = 'org.cocos2dx.demo'
DEFAULT_TARGET_ID = '1'
DEFAULT_PROJECT_NAME = "Hello"
echo -n " Input package path [ ${ DEFAULT_PACKAGE_PATH } ]: "
2011-05-20 17:40:28 +08:00
read PACKAGE_PATH
2013-06-04 22:21:41 +08:00
if [ " x ${ PACKAGE_PATH } " = = "x" ] ; then
PACKAGE_PATH = ${ DEFAULT_PACKAGE_PATH }
fi
${ ANDROID_CMD } list targets
echo -n " Input target id [ ${ DEFAULT_TARGET_ID } ]: "
2011-03-24 09:37:56 +08:00
read TARGET_ID
2013-06-04 22:21:41 +08:00
if [ " x ${ TARGET_ID } " = = "x" ] ; then
TARGET_ID = ${ DEFAULT_TARGET_ID }
fi
echo -n " Input your project name [ ${ DEFAULT_PROJECT_NAME } ]: "
2011-03-24 09:37:56 +08:00
read PROJECT_NAME
2013-06-04 22:21:41 +08:00
if [ " x ${ PROJECT_NAME } " = = "x" ] ; then
PROJECT_NAME = ${ DEFAULT_PROJECT_NAME }
fi
PROJECT_DIR = ` pwd ` /${ PROJECT_NAME }
2011-12-29 10:39:46 +08:00
# check if PROJECT_DIR is exist
2013-06-04 22:21:41 +08:00
if [ -d $PROJECT_DIR ] ; then
echo " $PROJECT_DIR already exist, please use another name "
2011-12-29 10:39:46 +08:00
exit
fi
2011-03-24 09:37:56 +08:00
2012-05-24 05:02:56 +08:00
# Make project directory
mkdir $PROJECT_DIR
# Create Android project inside proj.android
2013-06-04 22:21:41 +08:00
$ANDROID_CMD create project -n $PROJECT_NAME -t $TARGET_ID -k $PACKAGE_PATH -a $PROJECT_NAME -p $PROJECT_DIR /proj.android
$ANDROID_CMD update project -l ${ COCOS2DX_ROOT } /cocos2dx/platform/android/java -p $PROJECT_DIR /proj.android
2011-03-24 09:37:56 +08:00
}
2012-02-29 17:48:45 +08:00
check_param
2011-03-24 09:37:56 +08:00
create_android_project
2012-03-01 02:51:58 +08:00
if [ $0 = "linux" ] ; then
2011-12-23 16:00:31 +08:00
# invoked by create-linux-android-project.sh
2013-06-16 19:25:20 +08:00
ANDROID_SDK_ROOT = $ANDROID_SDK_ROOT COCOS2DX_ROOT = $COCOS2DX_ROOT sh $COCOS2DX_ROOT /template/linux/mycopy_files.sh $COCOS2DX_ROOT $PROJECT_NAME $NDK_ROOT $PACKAGE_PATH $USE_BOX2D $USE_CHIPMUNK $USE_LUA
2011-12-23 16:00:31 +08:00
else
# invoke template/android/copy_files.sh
2013-06-16 19:25:20 +08:00
ANDROID_SDK_ROOT = $ANDROID_SDK_ROOT COCOS2DX_ROOT = $COCOS2DX_ROOT sh $COCOS2DX_ROOT /template/android/copy_files.sh $COCOS2DX_ROOT $PROJECT_DIR $PACKAGE_PATH $USE_BOX2D $USE_CHIPMUNK $USE_LUA
2011-12-23 16:00:31 +08:00
fi