mirror of https://github.com/axmolengine/axmol.git
smarter script for creating android project
This commit is contained in:
parent
3cff8bee16
commit
c23267834b
|
@ -1,35 +1,43 @@
|
|||
#!/bin/bash
|
||||
# parameters passed to script
|
||||
# This script should be called by create-android-project.bat
|
||||
# or should be runned in linux shell. It can not be runned under
|
||||
# cygwin.
|
||||
# or should be runned in linux shell. It can not be runned under cygwin.
|
||||
# Don't modify the script until you know what you do.
|
||||
PARAMS=$@
|
||||
|
||||
# you can also set the environment here and uncomment them
|
||||
#NDK_ROOT=
|
||||
#ANDROID_SDK_ROOT
|
||||
#COCOS2DX_ROOT
|
||||
|
||||
# set environment paramters
|
||||
NDK_ROOT_LOCAL="/home/laschweinski/android/android-ndk-r5"
|
||||
ANDROID_SDK_ROOT_LOCAL="/home/laschweinski/android/android-sdk-linux_86"
|
||||
|
||||
NEED_BOX2D=false
|
||||
NEED_CHIPMUNK=false
|
||||
NEED_LUA=false
|
||||
|
||||
# try to get global variable
|
||||
if [ $NDK_ROOT"aaa" != "aaa" ]; then
|
||||
echo "use global definition of NDK_ROOT: $NDK_ROOT"
|
||||
NDK_ROOT_LOCAL=$NDK_ROOT
|
||||
if [ "x${NDK_ROOT}" == "x" ] ; then
|
||||
NDK_ROOT="/opt/android-ndk"
|
||||
fi
|
||||
|
||||
if [ $ANDROID_SDK_ROOT"aaa" != "aaa" ]; then
|
||||
echo "use global definition of ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT"
|
||||
ANDROID_SDK_ROOT_LOCAL=$ANDROID_SDK_ROOT
|
||||
if [ "x${ANDROID_SDK_ROOT}" == "x" ] ; then
|
||||
ANDROID_SDK_ROOT="/opt/android-sdk-update-manager"
|
||||
fi
|
||||
ANDROID_CMD="${ANDROID_SDK_ROOT}/tools/android"
|
||||
|
||||
if [ "x${COCOS2DX_ROOT}" == "x" ] ; then
|
||||
COCOS2DX_ROOT="${HOME}/cocos2d-x"
|
||||
if [ ! -d $COCOS2DX_ROOT ] ; then
|
||||
COCOS2DX_ROOT=`pwd`
|
||||
fi
|
||||
fi
|
||||
|
||||
# parameters passed to .bat or .sh
|
||||
PARAMS=
|
||||
if [ ! -d ${NDK_ROOT} -o ! -d ${ANDROID_SDK_ROOT} -o ! -x ${ANDROID_CMD} ] ; then
|
||||
echo "Please set the environment at first"
|
||||
fi
|
||||
|
||||
USE_BOX2D=false
|
||||
USE_CHIPMUNK=false
|
||||
USE_LUA=false
|
||||
|
||||
print_usage(){
|
||||
echo ERROR!!!
|
||||
echo usage
|
||||
echo "$0(or corresponding bat file on windows) [-b|--box2d] [-c|--chipmunk] [-l|--lua]"
|
||||
echo "usage:"
|
||||
echo "$0 [-b|--box2d] [-c|--chipmunk] [-l|--lua]"
|
||||
}
|
||||
|
||||
check_param(){
|
||||
|
@ -38,15 +46,15 @@ check_param(){
|
|||
case $param in
|
||||
-b | --box2d)
|
||||
echo using box2d
|
||||
NEED_BOX2D=true
|
||||
USE_BOX2D=true
|
||||
;;
|
||||
-c | --chipmunk)
|
||||
echo using chipmunk
|
||||
NEED_CHIPMUNK=true
|
||||
USE_CHIPMUNK=true
|
||||
;;
|
||||
-l | --lua)
|
||||
echo using lua
|
||||
NEED_LUA=true
|
||||
USE_LUA=true
|
||||
;;
|
||||
-linux)
|
||||
// skip it
|
||||
|
@ -56,80 +64,77 @@ check_param(){
|
|||
exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $NEED_BOX2D = "true" ]; then
|
||||
if [ $NEED_CHIPMUNK = "true" ]; then
|
||||
echo Warning!!!
|
||||
echo Use box2d and chipmunk together????
|
||||
fi
|
||||
|
||||
if [ $USE_BOX2D == "true" -a $USE_CHIPMUNK == "true" ] ; then
|
||||
echo '[WARN] Using box2d and chipmunk together!'
|
||||
fi
|
||||
}
|
||||
|
||||
# check if it was called by .bat file
|
||||
if [ $# -ge 5 ];then
|
||||
if [ $5 = "windows" ];then
|
||||
# called by .bat file
|
||||
length=`expr $# - 5`
|
||||
PARAMS=${@:6:$length}
|
||||
check_param
|
||||
sh $1/template/android/copy_files.sh $1 $2 $3 $4 $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
|
||||
exit
|
||||
fi
|
||||
if [ $# -ge 5 -a "x$5" == "xwindows" ] ; then
|
||||
# should be called by .bat file
|
||||
length=`expr $# - 5`
|
||||
PARAMS=${@:6:$length}
|
||||
check_param
|
||||
COCOS2DX_ROOT=$COCOS2DX_ROOT sh $COCOS2DX_ROOT/template/android/copy_files.sh $1 $2 $3 $4 $USE_BOX2D $USE_CHIPMUNK $USE_LUA
|
||||
exit
|
||||
fi
|
||||
|
||||
# the bash file should not be called by cygwin
|
||||
KERNEL_NAME=`uname -s | grep "CYGWIN*"`
|
||||
if [ $KERNEL_NAME"hi" != "hi" ]; then
|
||||
echo "Error!!!"
|
||||
echo "Don't run in cygwin. You should run corresponding bat."
|
||||
if [ "x$KERNEL_NAME" != "x" ] ; then
|
||||
echo "[ERROR] Don't run in cygwin. You should run .bat file"
|
||||
exit
|
||||
fi
|
||||
|
||||
# ok, it was run under linux
|
||||
|
||||
# check it was runned in cocos2d-x root
|
||||
check_path(){
|
||||
if [ ! -f create-android-project.sh ];then
|
||||
echo Error!!!
|
||||
echo Please run in cocos2dx root
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
create_android_project(){
|
||||
echo "Input package path. For example: org.cocos2dx.example"
|
||||
DEFAULT_PACKAGE_PATH='org.cocos2dx.demo'
|
||||
DEFAULT_TARGET_ID='1'
|
||||
DEFAULT_PROJECT_NAME="Hello"
|
||||
|
||||
echo -n "Input package path [${DEFAULT_PACKAGE_PATH}]:"
|
||||
read PACKAGE_PATH
|
||||
echo "Now cocos2d-x supports Android 2.2 or upper version"
|
||||
$ANDROID_SDK_ROOT_LOCAL/tools/android list targets
|
||||
echo "input target id:"
|
||||
if [ "x${PACKAGE_PATH}" == "x" ] ; then
|
||||
PACKAGE_PATH=${DEFAULT_PACKAGE_PATH}
|
||||
fi
|
||||
|
||||
${ANDROID_CMD} list targets
|
||||
echo -n "Input target id [${DEFAULT_TARGET_ID}]:"
|
||||
read TARGET_ID
|
||||
echo "input your project name:"
|
||||
if [ "x${TARGET_ID}" == "x" ] ; then
|
||||
TARGET_ID=${DEFAULT_TARGET_ID}
|
||||
fi
|
||||
|
||||
echo -n "Input your project name [${DEFAULT_PROJECT_NAME}]:"
|
||||
read PROJECT_NAME
|
||||
PROJECT_DIR=`pwd`/$PROJECT_NAME
|
||||
|
||||
if [ "x${PROJECT_NAME}" == "x" ] ; then
|
||||
PROJECT_NAME=${DEFAULT_PROJECT_NAME}
|
||||
fi
|
||||
PROJECT_DIR=`pwd`/${PROJECT_NAME}
|
||||
|
||||
# check if PROJECT_DIR is exist
|
||||
if [ -d $PROJECT_DIR ]; then
|
||||
echo "$PROJECT_DIR is exist, please use another name"
|
||||
if [ -d $PROJECT_DIR ] ; then
|
||||
echo "$PROJECT_DIR already exist, please use another name"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Make project directory
|
||||
mkdir $PROJECT_DIR
|
||||
# Create Android project inside proj.android
|
||||
$ANDROID_SDK_ROOT_LOCAL/tools/android create project -n $PROJECT_NAME -t $TARGET_ID -k $PACKAGE_PATH -a $PROJECT_NAME -p $PROJECT_DIR/proj.android
|
||||
$ANDROID_SDK_ROOT_LOCAL/tools/android update project -l cocos2dx/platform/android/java -p $PROJECT_DIR/proj.android
|
||||
$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
|
||||
}
|
||||
|
||||
check_path
|
||||
PARAMS=$@
|
||||
check_param
|
||||
create_android_project
|
||||
|
||||
if [ $0 = "linux" ]; then
|
||||
# invoked by create-linux-android-project.sh
|
||||
sh `pwd`/template/linux/mycopy_files.sh `pwd` $PROJECT_NAME $NDK_ROOT_LOCAL $PACKAGE_PATH $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
|
||||
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
|
||||
else
|
||||
# invoke template/android/copy_files.sh
|
||||
sh `pwd`/template/android/copy_files.sh `pwd` $PROJECT_NAME $NDK_ROOT_LOCAL $PACKAGE_PATH $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
|
||||
COCOS2DX_ROOT=$COCOS2DX_ROOT sh $COCOS2DX_ROOT/template/android/copy_files.sh $COCOS2DX_ROOT $PROJECT_DIR $PACKAGE_PATH $USE_BOX2D $USE_CHIPMUNK $USE_LUA
|
||||
fi
|
||||
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
#!/bin/sh
|
||||
PROJECT_PATH=${PWD}
|
||||
APPNAME="__projectname__"
|
||||
COCOS2DX_ROOT="__cocos2dxroot__"
|
||||
NDK_ROOT="__ndkroot__"
|
||||
DIR=$(cd `dirname $0`;pwd)
|
||||
APP_ROOT=$(cd $DIR/..;pwd)
|
||||
|
||||
# options
|
||||
|
||||
|
@ -16,35 +22,27 @@ OPTIONS:
|
|||
EOF
|
||||
}
|
||||
|
||||
while getopts "sh" OPTION; do
|
||||
case "$OPTION" in
|
||||
s)
|
||||
buildexternalsfromsource=1
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
while getopts "sh" OPTION ; do
|
||||
case "$OPTION" in
|
||||
s)
|
||||
buildexternalsfromsource=1
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# paths
|
||||
|
||||
if [ -z "${NDK_ROOT+aaa}" ];then
|
||||
echo "please define NDK_ROOT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
# ... use paths relative to current directory
|
||||
COCOS2DX_ROOT="$DIR/../.."
|
||||
APP_ROOT="$DIR/.."
|
||||
APP_ANDROID_ROOT="$DIR"
|
||||
|
||||
echo "NDK_ROOT = $NDK_ROOT"
|
||||
echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
|
||||
echo "APP_ROOT = $APP_ROOT"
|
||||
echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
|
||||
#echo "NDK_ROOT = $NDK_ROOT"
|
||||
#echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
|
||||
#echo "APP_ROOT = $APP_ROOT"
|
||||
#echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
|
||||
|
||||
# make sure assets is exist
|
||||
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
|
||||
|
@ -54,29 +52,20 @@ fi
|
|||
mkdir "$APP_ANDROID_ROOT"/assets
|
||||
|
||||
# copy resources
|
||||
for file in "$APP_ROOT"/Resources/*
|
||||
do
|
||||
if [ -d "$file" ]; then
|
||||
cp -rf "$file" "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
done
|
||||
cp -rf "$APP_ROOT"/Resources/* "$APP_ANDROID_ROOT"/assets
|
||||
|
||||
# copy icons (if they exist)
|
||||
file="$APP_ANDROID_ROOT"/assets/Icon-72.png
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-hdpi/icon.png
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-hdpi/icon.png
|
||||
fi
|
||||
file="$APP_ANDROID_ROOT"/assets/Icon-48.png
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-mdpi/icon.png
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-mdpi/icon.png
|
||||
fi
|
||||
file="$APP_ANDROID_ROOT"/assets/Icon-32.png
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-ldpi/icon.png
|
||||
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-ldpi/icon.png
|
||||
fi
|
||||
|
||||
|
||||
|
|
|
@ -1,59 +1,51 @@
|
|||
#!/bin/bash
|
||||
# check the args
|
||||
# $1: root of cocos2dx $2: app name $3: ndk root $4:pakcage path
|
||||
# $1: root of cocos2dx $2: app path $3: pakcage path
|
||||
|
||||
APP_NAME=$2
|
||||
COCOS2DX_ROOT=$1
|
||||
APP_DIR=$COCOS2DX_ROOT/$APP_NAME
|
||||
APP_DIR=$2
|
||||
PACKAGE_PATH=$3
|
||||
USE_BOX2D=$4
|
||||
USE_CHIPMUNK=$5
|
||||
USE_LUA=$6
|
||||
|
||||
APP_NAME=`basename ${APP_DIR}`
|
||||
HELLOWORLD_ROOT=$COCOS2DX_ROOT/samples/Cpp/HelloCpp
|
||||
COCOSJAVALIB_ROOT=$COCOS2DX_ROOT/cocos2dx/platform/android/java
|
||||
NDK_ROOT=$3
|
||||
PACKAGE_PATH=$4
|
||||
NEED_BOX2D=$5
|
||||
NEED_CHIPMUNK=$6
|
||||
NEED_LUA=$7
|
||||
|
||||
# xxx.yyy.zzz -> xxx/yyy/zzz
|
||||
convert_package_path_to_dir(){
|
||||
PACKAGE_PATH_DIR=`echo $1 | sed -e "s/\./\//g"`
|
||||
}
|
||||
|
||||
copy_cpp_h(){
|
||||
copy_cpp_h() {
|
||||
mkdir $APP_DIR/Classes
|
||||
for file in $COCOS2DX_ROOT/template/android/Classes/*
|
||||
do
|
||||
cp $file $APP_DIR/Classes
|
||||
done
|
||||
cp $COCOS2DX_ROOT/template/android/Classes/* $APP_DIR/Classes
|
||||
}
|
||||
|
||||
# copy resources
|
||||
copy_resouces(){
|
||||
copy_resouces() {
|
||||
mkdir $APP_DIR/Resources
|
||||
|
||||
for file in $HELLOWORLD_ROOT/Resources/iphone/*
|
||||
do
|
||||
cp -rf $file $APP_DIR/Resources
|
||||
done
|
||||
cp -rf $HELLOWORLD_ROOT/Resources/iphone/* $APP_DIR/Resources
|
||||
}
|
||||
|
||||
# from HelloWorld copy src and jni to APP_DIR
|
||||
copy_src_and_jni(){
|
||||
cp -rf $HELLOWORLD_ROOT/proj.android/jni $APP_DIR/proj.android
|
||||
cp -rf $HELLOWORLD_ROOT/proj.android/src $APP_DIR/proj.android
|
||||
copy_src_and_jni() {
|
||||
cp -rf $HELLOWORLD_ROOT/proj.android/{jni,src} $APP_DIR/proj.android
|
||||
|
||||
# replace Android.mk
|
||||
sh $COCOS2DX_ROOT/template/android/gamemk.sh $APP_DIR/proj.android/jni/Android.mk $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
|
||||
sh $COCOS2DX_ROOT/template/android/gamemk.sh $APP_DIR/proj.android/jni/Android.mk $USE_BOX2D $USE_CHIPMUNK $USE_LUA
|
||||
}
|
||||
|
||||
# copy build_native.sh and replace something
|
||||
copy_build_native(){
|
||||
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/proj.android/build_native.sh
|
||||
chmod u+x $APP_DIR/proj.android/build_native.sh
|
||||
}
|
||||
|
||||
# copy debugger script and replace templated parameters
|
||||
copy_ndkgdb(){
|
||||
copy_ndkgdb() {
|
||||
sed "s#__projectname__#$APP_NAME#;s#__packagename__#$PACKAGE_PATH#" $COCOS2DX_ROOT/template/android/ndkgdb.sh > $APP_DIR/proj.android/ndkgdb.sh
|
||||
chmod u+x $APP_DIR/proj.android/ndkgdb.sh
|
||||
}
|
||||
|
@ -71,7 +63,7 @@ modify_androidmanifest(){
|
|||
}
|
||||
|
||||
# modify HelloCpp.java
|
||||
modify_applicationdemo(){
|
||||
modify_applicationdemo() {
|
||||
convert_package_path_to_dir $PACKAGE_PATH
|
||||
|
||||
# rename APP_DIR/android/src/org/cocos2dx/hellocpp/HelloCpp.java to
|
||||
|
@ -80,13 +72,13 @@ modify_applicationdemo(){
|
|||
rm -fr $APP_DIR/proj.android/src/org/cocos2dx/hellocpp
|
||||
}
|
||||
|
||||
modify_layout(){
|
||||
modify_layout() {
|
||||
rm -f $APP_DIR/proj.android/res/layout/main.xml
|
||||
}
|
||||
|
||||
# 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(){
|
||||
copy_icon() {
|
||||
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
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
FILE=$1
|
||||
NEED_BOX2D=$2
|
||||
NEED_CHIPMUNK=$3
|
||||
NEED_LUA=$4
|
||||
USE_BOX2D=$2
|
||||
USE_CHIPMUNK=$3
|
||||
USE_LUA=$4
|
||||
|
||||
LOCAL_STATIC_LIBRARIES="LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static"
|
||||
MODULES_TO_CALL="\$(call import-module,CocosDenshion/android) \\
|
||||
|
@ -14,17 +14,17 @@ LOCAL_SRC_FILES="LOCAL_SRC_FILES := hellocpp/main.cpp \\
|
|||
../../Classes/AppDelegate.cpp \\
|
||||
../../Classes/HelloWorldScene.cpp"
|
||||
|
||||
if [ $NEED_BOX2D = "true" ];then
|
||||
if [ $USE_BOX2D = "true" ];then
|
||||
LOCAL_STATIC_LIBRARIES=$LOCAL_STATIC_LIBRARIES" box2d_static"
|
||||
MODULES_TO_CALL=$MODULES_TO_CALL" \$(call import-module,external/Box2D)"
|
||||
fi
|
||||
|
||||
if [ $NEED_CHIPMUNK = "true" ]; then
|
||||
if [ $USE_CHIPMUNK = "true" ]; then
|
||||
LOCAL_STATIC_LIBRARIES=$LOCAL_STATIC_LIBRARIES" chipmunk_static"
|
||||
MODULES_TO_CALL=$MODULES_TO_CALL" \$(call import-module,external/chipmunk)"
|
||||
fi
|
||||
|
||||
if [ $NEED_LUA = "true" ]; then
|
||||
if [ $USE_LUA = "true" ]; then
|
||||
LOCAL_STATIC_LIBRARIES=$LOCAL_STATIC_LIBRARIES" cocos_lua_static"
|
||||
MODULES_TO_CALL=$MODULES_TO_CALL" \$(call import-module,scripting/lua/proj.android)"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue