From ef9de9286c5f538f09888ed64da568def7ebb7f0 Mon Sep 17 00:00:00 2001 From: folecr Date: Sat, 15 Dec 2012 18:02:26 -1000 Subject: [PATCH 1/2] Setup user environment for building Android port. --- tools/android-buildsetup.sh | 85 +++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 tools/android-buildsetup.sh diff --git a/tools/android-buildsetup.sh b/tools/android-buildsetup.sh new file mode 100755 index 0000000000..1854d99b4d --- /dev/null +++ b/tools/android-buildsetup.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# Set up this cocos2d-x directory to build the Android port +# +# 1. Generate local.properties where necessary +# The END + +# exit this script if any commmand fails +set -e + +# read user.cfg if it exists and is readable + +_CFG_FILE=$(dirname "$0")"/user.cfg" +if [ -f "$_CFG_FILE" ] +then + [ -r "$_CFG_FILE" ] || die "Fatal Error: $_CFG_FILE exists but is unreadable" + . "$_CFG_FILE" +fi + +# paths + +if [ -z "${ANDROID_SDK_ROOT+aaa}" ]; then +# ... if ANDROID_SDK_ROOT is not set, use "$HOME/bin/android-sdk" + ANDROID_SDK_ROOT="$HOME/bin/android-sdk" +fi + +if [ -z "${ANDROID_NDK_ROOT+aaa}" ]; then +# ... if ANDROID_NDK_ROOT is not set, use "$HOME/bin/android-ndk" + ANDROID_NDK_ROOT="$HOME/bin/android-ndk" +fi + +# find current dir +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# find working dir +WORKINGDIR="$(pwd)" + +# paths with defaults hardcoded to relative paths + +if [ -z "${COCOS2DX_ROOT+aaa}" ]; then + COCOS2DX_ROOT="$WORKINGDIR" +fi + +if [ ! -f "$COCOS2DX_ROOT/tools/android-buildsetup.sh" ] +then + echo "Run..." + echo "> ./tools/android-buildsetup.sh" + echo "... from the top level of the cocos2d-x source tree" + echo "OR" + echo "Run..." + echo "> COCOS2DX_ROOT= /build/setupandroid.sh" + exit -1 +fi + +echo "Paths :" +echo " ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT" +echo " ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT" +echo " COCOS2DX_ROOT : $COCOS2DX_ROOT" +echo " WORKINGDIR : $WORKINGDIR" +echo " SCRIPTDIR : $SCRIPTDIR" + +_CONTENTS="" +_CONTENTS+="sdk.dir=$ANDROID_SDK_ROOT"'\n' +_CONTENTS+="NDK_ROOT=$ANDROID_NDK_ROOT"'\n' +echo +echo "--- local.properties" +echo "---" +echo -e "$_CONTENTS" +echo "---" + +_ANDROIDMANIFESTS=(`find "$COCOS2DX_ROOT/cocos2dx" -type f -name "AndroidManifest.xml"`) +_ANDROIDMANIFESTS+=(`find "$COCOS2DX_ROOT/samples" -type f -name "AndroidManifest.xml"`) + +for a in "${_ANDROIDMANIFESTS[@]}"; do + _LOCAL_PROPERTIES_FILE=${a/AndroidManifest\.xml/local\.properties} + +# write local.properties if it doesn't already exist + if [ -f "$_LOCAL_PROPERTIES_FILE" ] + then + echo "$_LOCAL_PROPERTIES_FILE exists. skipping overwrite" + else + echo "writing $_LOCAL_PROPERTIES_FILE" + echo -e "$_CONTENTS" > "$_LOCAL_PROPERTIES_FILE" + fi +done From 6dba49f25be997b1331d9622d1d4655f47701090 Mon Sep 17 00:00:00 2001 From: folecr Date: Fri, 15 Mar 2013 16:29:31 -0700 Subject: [PATCH 2/2] Android build_native.sh now reads local.properties for environment variables --- .../proj.android/build_native.sh | 16 ++++++++++++++- .../Cpp/HelloCpp/proj.android/build_native.sh | 16 ++++++++++++++- .../SimpleGame/proj.android/build_native.sh | 16 ++++++++++++++- .../Cpp/TestCpp/proj.android/build_native.sh | 16 ++++++++++++++- .../proj.android/build_native.sh | 16 ++++++++++++++- .../CocosPlayer/proj.android/build_native.sh | 16 ++++++++++++++- .../CrystalCraze/proj.android/build_native.sh | 16 ++++++++++++++- .../MoonWarriors/proj.android/build_native.sh | 16 ++++++++++++++- .../proj.android/build_native.sh | 16 ++++++++++++++- .../proj.android/build_native.sh | 16 ++++++++++++++- .../Lua/HelloLua/proj.android/build_native.sh | 16 ++++++++++++++- .../Lua/TestLua/proj.android/build_native.sh | 20 ++++++++++++++++--- 12 files changed, 182 insertions(+), 14 deletions(-) diff --git a/samples/Cpp/AssetsManagerTest/proj.android/build_native.sh b/samples/Cpp/AssetsManagerTest/proj.android/build_native.sh index cb259185b6..15e1e45299 100755 --- a/samples/Cpp/AssetsManagerTest/proj.android/build_native.sh +++ b/samples/Cpp/AssetsManagerTest/proj.android/build_native.sh @@ -28,10 +28,24 @@ exit 0 esac done +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Cpp/HelloCpp/proj.android/build_native.sh b/samples/Cpp/HelloCpp/proj.android/build_native.sh index 62f06fef17..5a91b70245 100755 --- a/samples/Cpp/HelloCpp/proj.android/build_native.sh +++ b/samples/Cpp/HelloCpp/proj.android/build_native.sh @@ -28,10 +28,24 @@ exit 0 esac done +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Cpp/SimpleGame/proj.android/build_native.sh b/samples/Cpp/SimpleGame/proj.android/build_native.sh index 8c5d1571a1..29be776c45 100755 --- a/samples/Cpp/SimpleGame/proj.android/build_native.sh +++ b/samples/Cpp/SimpleGame/proj.android/build_native.sh @@ -28,10 +28,24 @@ exit 0 esac done +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Cpp/TestCpp/proj.android/build_native.sh b/samples/Cpp/TestCpp/proj.android/build_native.sh index 0e9d1e8161..9172deb176 100755 --- a/samples/Cpp/TestCpp/proj.android/build_native.sh +++ b/samples/Cpp/TestCpp/proj.android/build_native.sh @@ -28,10 +28,24 @@ exit 0 esac done +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Javascript/CocosDragonJS/proj.android/build_native.sh b/samples/Javascript/CocosDragonJS/proj.android/build_native.sh index f97b2efb03..a897fde8c3 100755 --- a/samples/Javascript/CocosDragonJS/proj.android/build_native.sh +++ b/samples/Javascript/CocosDragonJS/proj.android/build_native.sh @@ -37,10 +37,24 @@ done # exit this script if any commmand fails set -e +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Javascript/CocosPlayer/proj.android/build_native.sh b/samples/Javascript/CocosPlayer/proj.android/build_native.sh index e1856727dd..3e02fd73b5 100755 --- a/samples/Javascript/CocosPlayer/proj.android/build_native.sh +++ b/samples/Javascript/CocosPlayer/proj.android/build_native.sh @@ -37,10 +37,24 @@ done # exit this script if any commmand fails set -e +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Javascript/CrystalCraze/proj.android/build_native.sh b/samples/Javascript/CrystalCraze/proj.android/build_native.sh index 1513a7143b..11415396fa 100755 --- a/samples/Javascript/CrystalCraze/proj.android/build_native.sh +++ b/samples/Javascript/CrystalCraze/proj.android/build_native.sh @@ -37,10 +37,24 @@ done # exit this script if any commmand fails set -e +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Javascript/MoonWarriors/proj.android/build_native.sh b/samples/Javascript/MoonWarriors/proj.android/build_native.sh index f1d15d8cde..92128a413e 100755 --- a/samples/Javascript/MoonWarriors/proj.android/build_native.sh +++ b/samples/Javascript/MoonWarriors/proj.android/build_native.sh @@ -36,10 +36,24 @@ done # exit this script if any commmand fails set -e +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Javascript/TestJavascript/proj.android/build_native.sh b/samples/Javascript/TestJavascript/proj.android/build_native.sh index 052c09b169..3bae11c304 100755 --- a/samples/Javascript/TestJavascript/proj.android/build_native.sh +++ b/samples/Javascript/TestJavascript/proj.android/build_native.sh @@ -36,10 +36,24 @@ done # exit this script if any commmand fails set -e +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Javascript/WatermelonWithMe/proj.android/build_native.sh b/samples/Javascript/WatermelonWithMe/proj.android/build_native.sh index cff7fb022c..8545f0a954 100755 --- a/samples/Javascript/WatermelonWithMe/proj.android/build_native.sh +++ b/samples/Javascript/WatermelonWithMe/proj.android/build_native.sh @@ -36,10 +36,24 @@ done # exit this script if any commmand fails set -e +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Lua/HelloLua/proj.android/build_native.sh b/samples/Lua/HelloLua/proj.android/build_native.sh index 02af15c7f5..70e662a0d8 100755 --- a/samples/Lua/HelloLua/proj.android/build_native.sh +++ b/samples/Lua/HelloLua/proj.android/build_native.sh @@ -28,10 +28,24 @@ exit 0 esac done +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths if [ -z "${NDK_ROOT+aaa}" ];then -echo "please define NDK_ROOT" +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" exit 1 fi diff --git a/samples/Lua/TestLua/proj.android/build_native.sh b/samples/Lua/TestLua/proj.android/build_native.sh index d918e10c90..98b3e28524 100755 --- a/samples/Lua/TestLua/proj.android/build_native.sh +++ b/samples/Lua/TestLua/proj.android/build_native.sh @@ -28,11 +28,25 @@ exit 0 esac done +# read local.properties + +_LOCALPROPERTIES_FILE=$(dirname "$0")"/local.properties" +if [ -f "$_LOCALPROPERTIES_FILE" ] +then + [ -r "$_LOCALPROPERTIES_FILE" ] || die "Fatal Error: $_LOCALPROPERTIES_FILE exists but is unreadable" + + # strip out entries with a "." because Bash cannot process variables with a "." + _PROPERTIES=`sed '/\./d' "$_LOCALPROPERTIES_FILE"` + for line in "$_PROPERTIES"; do + declare "$line"; + done +fi + # paths -if [ -z "${NDK_ROOT+aaa}" ]; then -# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk" - NDK_ROOT="$HOME/bin/android-ndk" +if [ -z "${NDK_ROOT+aaa}" ];then +echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties" +exit 1 fi if [ -z "${COCOS2DX_ROOT+aaa}" ]; then