Skip to content

Commit

Permalink
issue #982: android template support lua box2d and chipmunk
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo committed Feb 29, 2012
1 parent bb2ca44 commit c0d2118
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 50 deletions.
2 changes: 1 addition & 1 deletion create-android-project.bat
Expand Up @@ -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
62 changes: 56 additions & 6 deletions create-android-project.sh
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion create-linux-eclipse-project.sh
Expand Up @@ -6,4 +6,4 @@

# set environment paramters

sh `pwd`/create-android-project.sh linux
sh `pwd`/create-android-project.sh linux $@
25 changes: 0 additions & 25 deletions template/android/AndroidTemplate1.mk

This file was deleted.

10 changes: 0 additions & 10 deletions template/android/AndroidTemplate2.mk

This file was deleted.

3 changes: 0 additions & 3 deletions template/android/Application.mk

This file was deleted.

25 changes: 25 additions & 0 deletions template/android/application.sh
@@ -0,0 +1,25 @@
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+=" box2d_shared"
fi

if [ $NEED_CHIPMUNK == "true" ]; then
APP_MODULES+=" chipmunk_shared"
fi

if [ $NEED_LUA == "true" ]; then
APP_MODULES+=" lua_shared"
fi

APP_MODULES+=" game_shared"

cat > $FILE << EOF
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
$APP_MODULES
EOF
46 changes: 46 additions & 0 deletions template/android/classesmk.sh
@@ -0,0 +1,46 @@
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+=" box2d_shared"
fi

if [ $NEED_CHIPMUNK == "true" ]; then
LOCAL_SHARED_LIBRARIES+=" chipmunk_shared"
fi

if [ $NEED_LUA == "true" ]; then
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
26 changes: 22 additions & 4 deletions template/android/copy_files.sh
Expand Up @@ -7,6 +7,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(){
Expand Down Expand Up @@ -57,8 +60,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
Expand All @@ -80,11 +85,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+='System.loadLibrary("box2d");'
fi

if [ $NEED_CHIPMUNK == "true" ]; then
CONTENT+='System.loadLibrary("chipmunk");'
fi

if [ $NEED_LUA == "true" ]; then
CONTENT+='System.loadLibrary("lua");'
fi

sed -i "/cocosdenshion/ i\ $CONTENT" $APP_DIR/android/src/$PACKAGE_PATH_DIR/$APP_NAME.java
}

modify_layout(){
Expand Down
46 changes: 46 additions & 0 deletions template/android/gamemk.sh
@@ -0,0 +1,46 @@
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+=" box2d_shared"
fi

if [ $NEED_CHIPMUNK == "true" ]; then
LOCAL_SHARED_LIBRARIES+=" chipmunk_shared"
fi

if [ $NEED_LUA == "true" ]; then
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
31 changes: 31 additions & 0 deletions template/android/gamestaticmk.sh
@@ -0,0 +1,31 @@
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

0 comments on commit c0d2118

Please sign in to comment.