Merge pull request #737 from minggo/iss982_box2d_template

Iss982 android template
This commit is contained in:
minggo 2012-02-29 19:26:12 -08:00
commit a8a82ec7ec
11 changed files with 239 additions and 52 deletions

View File

@ -45,6 +45,6 @@ for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%cd%"') do set _CURRENTDIR=%%A
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%_NDKROOT%"') do set _NDKROOT=%%A
:: Throw away temporary env vars and invoke script, passing any args that were passed to us
endlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% %_PACKAGEPATH% "windows"
endlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% %_PACKAGEPATH% "windows" -b
pause

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# This script should be called by create-android-project.bat
# or should be runned in linux shell. It can not be runned under
# cygwin.
@ -8,6 +8,10 @@
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"
@ -19,16 +23,60 @@ if [ $ANDROID_SDK_ROOT"aaa" != "aaa" ]; then
ANDROID_SDK_ROOT_LOCAL=$ANDROID_SDK_ROOT
fi
# parameters passed to .bat or .sh
PARAMS=
print_usage(){
echo ERROR!!!
echo usage
echo "$0(or corresponding bat file on windows) [-b|--box2d] [-c|--chipmunk] [-l|--lua]"
}
check_param(){
for param in ${PARAMS[@]}
do
case $param in
-b | --box2d)
echo using box2d
NEED_BOX2D=true
;;
-c | --chipmunk)
echo using chipmunk
NEED_CHIPMUNK=true
;;
-l | --lua)
echo using lua
NEED_LUA=true
;;
-linux)
// skip it
;;
*)
print_usage
exit 1
esac
done
if [ $NEED_BOX2D = "true" ]; then
if [ $NEED_CHIPMUNK = "true" ]; then
echo Warning!!!
echo Use box2d and chipmunk together????
fi
fi
}
# check if it was called by .bat file
if [ $# -eq 5 ];then
if [ $# -ge 5 ];then
if [ $5 = "windows" ];then
# called by .bat file
sh $1/template/android/copy_files.sh $1 $2 $3 $4
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
fi
# the bash file should not be called by cygwin
KERNEL_NAME=`uname -s | grep "CYGWIN*"`
if [ $KERNEL_NAME"hi" != "hi" ]; then
@ -70,13 +118,15 @@ create_android_project(){
}
check_path
PARAMS=$@
check_param
create_android_project
if [ $# -eq 1 ]; then
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
sh `pwd`/template/linux/mycopy_files.sh `pwd` $PROJECT_NAME $NDK_ROOT_LOCAL $PACKAGE_PATH $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
else
# invoke template/android/copy_files.sh
sh `pwd`/template/android/copy_files.sh `pwd` $PROJECT_NAME $NDK_ROOT_LOCAL $PACKAGE_PATH
sh `pwd`/template/android/copy_files.sh `pwd` $PROJECT_NAME $NDK_ROOT_LOCAL $PACKAGE_PATH $NEED_BOX2D $NEED_CHIPMUNK $NEED_LUA
fi

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# This script should be called by create-android-project.bat
# or should be runned in linux shell. It can not be runned under
# cygwin.
@ -6,4 +6,4 @@
# set environment paramters
sh `pwd`/create-android-project.sh linux
bash `pwd`/create-android-project.sh -linux $@

View File

@ -1,25 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := main.cpp
LOCAL_STATIC_LIBRARIES := png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
LOCAL_STATIC_LIBRARIES += curl_static_prebuilt
LOCAL_WHOLE_STATIC_LIBRARIES := game_logic_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_SHARED_LIBRARIES := cocosdenshion_shared
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx/platform/third_party/android/modules/libcurl)
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

View File

@ -1,10 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
subdirs := $(addprefix $(LOCAL_PATH)/../../../,$(addsuffix /Android.mk, \
cocos2dx \
CocosDenshion/android \
))
subdirs += $(LOCAL_PATH)/../../Classes/Android.mk $(LOCAL_PATH)/helloworld/Android.mk
include $(subdirs)

View File

@ -1,3 +0,0 @@
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_MODULES := cocos2dx_static cocosdenshion_shared game_logic_static game_shared

View File

@ -0,0 +1,27 @@
#!/bin/bash
FILE=$1
NEED_BOX2D=$2
NEED_CHIPMUNK=$3
NEED_LUA=$4
APP_MODULES="APP_MODULES := cocos2dx_static cocosdenshion_shared"
if [ $NEED_BOX2D = "true" ];then
APP_MODULES=$APP_MODULES" box2d_shared"
fi
if [ $NEED_CHIPMUNK = "true" ]; then
APP_MODULES=$APP_MODULES" chipmunk_shared"
fi
if [ $NEED_LUA = "true" ]; then
APP_MODULES=$APP_MODULES" lua_shared"
fi
APP_MODULES=$APP_MODULES" game_shared"
cat > $FILE << EOF
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
$APP_MODULES
EOF

View File

@ -0,0 +1,48 @@
#!/bin/bash
FILE=$1
NEED_BOX2D=$2
NEED_CHIPMUNK=$3
NEED_LUA=$4
LOCAL_SHARED_LIBRARIES="LOCAL_SHARED_LIBRARIES := cocosdenshion_shared"
if [ $NEED_BOX2D = "true" ];then
LOCAL_SHARED_LIBRARIES=$LOCAL_SHARED_LIBRARIES" box2d_shared"
fi
if [ $NEED_CHIPMUNK = "true" ]; then
LOCAL_SHARED_LIBRARIES=$LOCAL_SHARED_LIBRARIES" chipmunk_shared"
fi
if [ $NEED_LUA = "true" ]; then
LOCAL_SHARED_LIBRARIES=$LOCAL_SHARED_LIBRARIES" lua_shared"
fi
cat > $FILE << EOF
LOCAL_PATH := \$(call my-dir)
include \$(CLEAR_VARS)
LOCAL_MODULE := game_logic_static
LOCAL_MODULE_FILENAME := libgame_logic
LOCAL_SRC_FILES := AppDelegate.cpp \\
HelloWorldScene.cpp
LOCAL_EXPORT_C_INCLUDES := \$(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
$LOCAL_SHARED_LIBRARIES
include \$(BUILD_STATIC_LIBRARY)
\$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
\$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
\$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)
EOF

View File

@ -1,3 +1,4 @@
#!/bin/bash
# check the args
# $1: root of cocos2dx $2: app name $3: ndk root $4:pakcage path
@ -7,6 +8,9 @@ APP_DIR=$COCOS2DX_ROOT/$APP_NAME
HELLOWORLD_ROOT=$COCOS2DX_ROOT/HelloWorld
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(){
@ -57,8 +61,10 @@ copy_src_and_jni(){
cp -rf $HELLOWORLD_ROOT/android/src $APP_DIR/android
# repalce Android.mk and Application.mk
cat $COCOS2DX_ROOT/template/android/AndroidTemplate1.mk > $APP_DIR/android/jni/helloworld/Android.mk
cat $COCOS2DX_ROOT/template/android/Application.mk > $APP_DIR/android/jni/Application.mk
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
}
# copy build_native.sh and replace something
@ -80,11 +86,24 @@ modify_applicationdemo(){
# 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
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/tempfile.java
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
rm -fr $APP_DIR/android/src/org/cocos2dx/application
mv $APP_DIR/android/src/$PACKAGE_PATH_DIR/tempfile.java $APP_DIR/android/src/$PACKAGE_PATH_DIR/$APP_NAME.java
# load need .so
CONTENT=
if [ $NEED_BOX2D = "true" ];then
CONTENT=$CONTENT'System.loadLibrary("box2d");'
fi
if [ $NEED_CHIPMUNK = "true" ]; then
CONTENT=$CONTENT'System.loadLibrary("chipmunk");'
fi
if [ $NEED_LUA = "true" ]; then
CONTENT=$CONTENT'System.loadLibrary("lua");'
fi
sed -i "/cocosdenshion/ i\ $CONTENT" $APP_DIR/android/src/$PACKAGE_PATH_DIR/$APP_NAME.java
}
modify_layout(){

View File

@ -0,0 +1,48 @@
#!/bin/bash
FILE=$1
NEED_BOX2D=$2
NEED_CHIPMUNK=$3
NEED_LUA=$4
LOCAL_SHARED_LIBRARIES="LOCAL_SHARED_LIBRARIES := cocosdenshion_shared"
if [ $NEED_BOX2D = "true" ];then
LOCAL_SHARED_LIBRARIES=$LOCAL_SHARED_LIBRARIES" box2d_shared"
fi
if [ $NEED_CHIPMUNK = "true" ]; then
LOCAL_SHARED_LIBRARIES=$LOCAL_SHARED_LIBRARIES" chipmunk_shared"
fi
if [ $NEED_LUA = "true" ]; then
LOCAL_SHARED_LIBRARIES=$LOCAL_SHARED_LIBRARIES" lua_shared"
fi
cat > $FILE << EOF
LOCAL_PATH := \$(call my-dir)
include \$(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := main.cpp
LOCAL_STATIC_LIBRARIES := png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
LOCAL_STATIC_LIBRARIES += curl_static_prebuilt
LOCAL_WHOLE_STATIC_LIBRARIES := game_logic_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
$LOCAL_SHARED_LIBRARIES
include \$(BUILD_SHARED_LIBRARY)
\$(call import-module,cocos2dx/platform/third_party/android/modules/libcurl)
\$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
\$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
\$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)
EOF

View File

@ -0,0 +1,33 @@
#!/bin/bash
FILE=$1
NEED_BOX2D=$2
NEED_CHIPMUNK=$3
NEED_LUA=$4
if [ $NEED_BOX2D = "true" ];then
BOX2D="Box2D"
fi
if [ $NEED_CHIPMUNK = "true" ]; then
CHIPMUNK="chipmunk"
fi
if [ $NEED_LUA = "true" ]; then
LUA="lua/proj.android/jni"
fi
cat > $FILE << EOF
LOCAL_PATH := \$(call my-dir)
include \$(CLEAR_VARS)
subdirs := \$(addprefix \$(LOCAL_PATH)/../../../,\$(addsuffix /Android.mk, \\
cocos2dx \\
CocosDenshion/android \\
$BOX2D $CHIPMUNK $LUA \\
))
subdirs += \$(LOCAL_PATH)/../../Classes/Android.mk \$(LOCAL_PATH)/helloworld/Android.mk
include \$(subdirs)
EOF