Merge pull request #4083 from minggo/build-script-template

[ci skip]use python script to build android template projects
This commit is contained in:
minggo 2013-11-04 00:53:40 -08:00
commit bca254499e
11 changed files with 310 additions and 557 deletions

View File

@ -19,7 +19,8 @@ cocos2d-x-3.0alpha1 @??? 2013
[FIX] Fixed application will crash when pause and resume.
[FIX] Clear NoSuchMethodError Exception when JniHelper fails to find method id
[NEW] Added xlargeScreens="true" to supports-screens
[NEW] Added build/android-build.py to build all Android samples
[NEW] Added build/android-build.py to build all Android samples, and remove all build_native.sh/cmd
[NEW] Added build_native.py to build template projects, and remove build_native.sh/cmd
[Mac]
[FIX] Removed unused CCLOG() from GL initialization
[iOS]

View File

@ -2,10 +2,6 @@
# android-build.py
# Build android samples
# You can use
# begin
import sys
import os, os.path
import shutil

View File

@ -1,83 +0,0 @@
@echo off
set APPNAME="HelloCpp"
set buildexternalsfromsource=
set PARALLEL_BUILD_FLAG=
goto :getopts
:usage
echo Build C/C++ code for %APPNAME% using Android NDK
echo OPTIONS:
echo -s Build externals from source
echo -h this help
pause
exit /b 1
:def
echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment."
pause
exit /b 1
:getopts
set "par=%~1"
if "%par%"=="" (goto :L)
if "%~1"=="-s" set /a buildexternalsfromsource=1
if "%~1"=="-h" goto :usage
shift
goto :getopts
:L
set NDK_ROOT=%NDK_ROOT%
if "%NDK_ROOT%"=="" goto:def
rem check toolchains
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.8 (goto :toolchains48)
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.7 (goto :toolchains47)
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.6 (goto :toolchains46)
echo "Couldn't find the gcc toolchain."
pause
exit /b 1
:toolchains48
set NDK_TOOLCHAIN_VERSION=4.8
goto :InitPath
:toolchains47
set NDK_TOOLCHAIN_VERSION=4.7
goto :InitPath
:toolchains46
set NDK_TOOLCHAIN_VERSION=4.6
:InitPath
set COCOS2DX_ROOT=%~dp0..\..\..
set APP_ROOT=%~dp0..
set APP_ANDROID_ROOT=%~dp0
if "%buildexternalsfromsource%"=="1" (goto :MODULE1) else (goto :MODULE2)
:MODULE1
echo "Building external dependencies from source"
set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%\cocos2dx\platform\third_party\android\source
goto :COPY_RES
:MODULE2
echo "Using prebuilt externals"
set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%\cocos;%COCOS2DX_ROOT%\external
:COPY_RES
echo NDK_ROOT = %NDK_ROOT%
echo COCOS2DX_ROOT=%COCOS2DX_ROOT%
echo APP_ROOT=%APP_ROOT%
echo APP_ANDROID_ROOT=%APP_ANDROID_ROOT%
echo NDK_TOOLCHAIN_VERSION=%NDK_TOOLCHAIN_VERSION%
rem make sure assets is exist
if exist %APP_ANDROID_ROOT%\assets rd /q /s %APP_ANDROID_ROOT%\assets
mkdir %APP_ANDROID_ROOT%\assets
rem copy Resources/* into assets' root
xcopy /e /q /r /y %APP_ROOT%\Resources\* %APP_ANDROID_ROOT%\assets
call %NDK_ROOT%\ndk-build.cmd NDK_LOG=0 V=0 %*
pause

View File

@ -0,0 +1,100 @@
#!/usr/bin/python
# build_native.py
# Build native codes
import sys
import os, os.path
import shutil
def check_environment_variables():
''' Checking the environment NDK_ROOT, which will be used for building
'''
try:
NDK_ROOT = os.environ['NDK_ROOT']
except Exception:
print "NDK_ROOT not defined. Please define NDK_ROOT in your environment"
sys.exit(1)
return NDK_ROOT
def select_toolchain_version():
'''Because ndk-r8e uses gcc4.6 as default. gcc4.6 doesn't support c++11. So we should select gcc4.7 when
using ndk-r8e. But gcc4.7 is removed in ndk-r9, so we should determine whether gcc4.7 exist.
Conclution:
ndk-r8e -> use gcc4.7
ndk-r9 -> use gcc4.8
'''
ndk_root = check_environment_variables()
if os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.8")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.8'
print "The Selected NDK toolchain version was 4.8 !"
elif os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.7")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.7'
print "The Selected NDK toolchain version was 4.7 !"
else:
print "Couldn't find the gcc toolchain."
exit(1)
def do_build(cocos_root, ndk_root, app_android_root):
ndk_path = os.path.join(ndk_root, "ndk-build")
# windows should use ";" to seperate module paths
platform = sys.platform
if platform == 'win32':
ndk_module_path = 'NDK_MODULE_PATH=%s;%s/external;%s/cocos' % (cocos_root, cocos_root, cocos_root)
else:
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
ndk_build_param = sys.argv[1:]
if len(ndk_build_param) == 0:
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
else:
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
os.system(command)
def copy_files(src, dst):
for item in os.listdir(src):
path = os.path.join(src, item)
# Android can not package the file that ends with ".gz"
if not item.startswith('.') and not item.endswith('.gz') and os.path.isfile(path):
shutil.copy(path, dst)
if os.path.isdir(path):
new_dst = os.path.join(dst, item)
os.mkdir(new_dst)
copy_files(path, new_dst)
def copy_resources(app_android_root):
# remove app_android_root/assets if it exists
assets_dir = os.path.join(app_android_root, "assets")
if os.path.isdir(assets_dir):
shutil.rmtree(assets_dir)
# copy resources
os.mkdir(assets_dir)
resources_dir = os.path.join(app_android_root, "../Resources")
if os.path.isdir(resources_dir):
copy_files(resources_dir, assets_dir)
def build():
ndk_root = check_environment_variables()
select_toolchain_version()
current_dir = os.path.dirname(os.path.realpath(__file__))
cocos_root = os.path.join(current_dir, "../../..")
app_android_root = current_dir
copy_resources(app_android_root)
do_build(cocos_root, ndk_root, app_android_root)
# -------------- main --------------
if __name__ == '__main__':
build()

View File

@ -1,91 +0,0 @@
APPNAME="HelloCpp"
# options
buildexternalsfromsource=
usage(){
cat << EOF
usage: $0 [options]
Build C/C++ code for $APPNAME using Android NDK
OPTIONS:
-s Build externals from source
-h this help
EOF
}
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
# For compatibility of android-ndk-r9, 4.7 was removed from r9
if [ -d "${NDK_ROOT}/toolchains/arm-linux-androideabi-4.7" ]; then
export NDK_TOOLCHAIN_VERSION=4.7
echo "The Selected NDK toolchain version was 4.7 !"
else
if [ -d "${NDK_ROOT}/toolchains/arm-linux-androideabi-4.8" ]; then
export NDK_TOOLCHAIN_VERSION=4.8
echo "The Selected NDK toolchain version was 4.8 !"
else
echo "Couldn't find the gcc toolchain."
exit 1
fi
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"
# make sure assets is exist
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
rm -rf "$APP_ANDROID_ROOT"/assets
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
# run ndk-build
if [[ "$buildexternalsfromsource" ]]; then
echo "Building external dependencies from source"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos:${COCOS2DX_ROOT}/external"
else
echo "Using prebuilt externals"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos:${COCOS2DX_ROOT}/external"
fi

View File

@ -1,90 +0,0 @@
@echo off
set APPNAME="HelloJavascript"
set buildexternalsfromsource=
set PARALLEL_BUILD_FLAG=
goto :getopts
:usage
echo Build C/C++ code for %APPNAME% using Android NDK
echo OPTIONS:
echo -s Build externals from source
echo -p Run make with -j8 option to take advantage of multiple processors
echo -h this help
pause
exit /b 1
:def
echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment."
pause
exit /b 1
:getopts
set "par=%~1"
if "%par%"=="" (goto :L)
if "%~1"=="-s" set /a buildexternalsfromsource=1
if "%~1"=="-p" set PARALLEL_BUILD_FLAG=\-j8
if "%~1"=="-h" goto :usage
shift
goto :getopts
:L
set NDK_ROOT=%NDK_ROOT%
if "%NDK_ROOT%"=="" goto:def
rem check toolchains
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.8 (goto :toolchains48)
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.7 (goto :toolchains47)
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.6 (goto :toolchains46)
echo "Couldn't find the gcc toolchain."
pause
exit /b 1
:toolchains48
set NDK_TOOLCHAIN_VERSION=4.8
goto :InitPath
:toolchains47
set NDK_TOOLCHAIN_VERSION=4.7
goto :InitPath
:toolchains46
set NDK_TOOLCHAIN_VERSION=4.6
:InitPath
set COCOS2DX_ROOT=%~dp0..\..\..
set APP_ROOT=%~dp0..
set APP_ANDROID_ROOT=%~dp0
set BINDINGS_JS_ROOT=%COCOS2DX_ROOT%\cocos\scripting\javascript\script
if "%buildexternalsfromsource%"=="1" (goto :MODULE1) else (goto :MODULE2)
:MODULE1
echo "Building external dependencies from source"
set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%\cocos2dx\platform\third_party\android\source
goto :COPY_RES
:MODULE2
echo "Using prebuilt externals"
set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%\cocos;%COCOS2DX_ROOT%\external
:COPY_RES
echo NDK_ROOT = %NDK_ROOT%
echo COCOS2DX_ROOT=%COCOS2DX_ROOT%
echo APP_ROOT=%APP_ROOT%
echo APP_ANDROID_ROOT=%APP_ANDROID_ROOT%
echo NDK_TOOLCHAIN_VERSION=%NDK_TOOLCHAIN_VERSION%
rem make sure assets is exist
if exist %APP_ANDROID_ROOT%\assets rd /q /s %APP_ANDROID_ROOT%\assets
mkdir %APP_ANDROID_ROOT%\assets
mkdir %APP_ANDROID_ROOT%\assets\res
rem copy Resources/* into assets' root
xcopy /e /q /r /y %APP_ROOT%\Resources\* %APP_ANDROID_ROOT%\assets
rem copy bindings/*.js into assets' root
xcopy /e /q /r /y %BINDINGS_JS_ROOT%\* %APP_ANDROID_ROOT%\assets
call %NDK_ROOT%\ndk-build.cmd %PARALLEL_BUILD_FLAG% NDK_LOG=0 V=0 %*
pause

View File

@ -0,0 +1,104 @@
#!/usr/bin/python
# build_native.py
# Build native codes
import sys
import os, os.path
import shutil
def check_environment_variables():
''' Checking the environment NDK_ROOT, which will be used for building
'''
try:
NDK_ROOT = os.environ['NDK_ROOT']
except Exception:
print "NDK_ROOT not defined. Please define NDK_ROOT in your environment"
sys.exit(1)
return NDK_ROOT
def select_toolchain_version():
'''Because ndk-r8e uses gcc4.6 as default. gcc4.6 doesn't support c++11. So we should select gcc4.7 when
using ndk-r8e. But gcc4.7 is removed in ndk-r9, so we should determine whether gcc4.7 exist.
Conclution:
ndk-r8e -> use gcc4.7
ndk-r9 -> use gcc4.8
'''
ndk_root = check_environment_variables()
if os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.8")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.8'
print "The Selected NDK toolchain version was 4.8 !"
elif os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.7")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.7'
print "The Selected NDK toolchain version was 4.7 !"
else:
print "Couldn't find the gcc toolchain."
exit(1)
def do_build(cocos_root, ndk_root, app_android_root):
ndk_path = os.path.join(ndk_root, "ndk-build")
# windows should use ";" to seperate module paths
platform = sys.platform
if platform == 'win32':
ndk_module_path = 'NDK_MODULE_PATH=%s;%s/external;%s/cocos' % (cocos_root, cocos_root, cocos_root)
else:
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
ndk_build_param = sys.argv[1:]
if len(ndk_build_param) == 0:
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
else:
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
os.system(command)
def copy_files(src, dst):
for item in os.listdir(src):
path = os.path.join(src, item)
# Android can not package the file that ends with ".gz"
if not item.startswith('.') and not item.endswith('.gz') and os.path.isfile(path):
shutil.copy(path, dst)
if os.path.isdir(path):
new_dst = os.path.join(dst, item)
os.mkdir(new_dst)
copy_files(path, new_dst)
def copy_resources(app_android_root):
# remove app_android_root/assets if it exists
assets_dir = os.path.join(app_android_root, "assets")
if os.path.isdir(assets_dir):
shutil.rmtree(assets_dir)
# copy resources
os.mkdir(assets_dir)
resources_dir = os.path.join(app_android_root, "../Resources")
if os.path.isdir(resources_dir):
copy_files(resources_dir, assets_dir)
# jsb project should copy javascript files and resources(shared with cocos2d-html5)
resources_dir = os.path.join(app_android_root, "../../../cocos/scripting/javascript/script")
copy_files(resources_dir, assets_dir)
def build():
ndk_root = check_environment_variables()
select_toolchain_version()
current_dir = os.path.dirname(os.path.realpath(__file__))
cocos_root = os.path.join(current_dir, "../../..")
app_android_root = current_dir
copy_resources(app_android_root)
do_build(cocos_root, ndk_root, app_android_root)
# -------------- main --------------
if __name__ == '__main__':
build()

View File

@ -1,100 +0,0 @@
APPNAME="HelloJavascript"
# options
buildexternalsfromsource=
PARALLEL_BUILD_FLAG=
usage(){
cat << EOF
usage: $0 [options]
Build C/C++ code for $APPNAME using Android NDK
OPTIONS:
-s Build externals from source
-p Run make with -j8 option to take advantage of multiple processors
-h this help
EOF
}
while getopts "sph" OPTION; do
case "$OPTION" in
s)
buildexternalsfromsource=1
;;
p)
PARALLEL_BUILD_FLAG=\-j8
;;
h)
usage
exit 0
;;
esac
done
# exit this script if any commmand fails
set -e
# paths
if [ -z "${NDK_ROOT+aaa}" ];then
echo "please define NDK_ROOT"
exit 1
fi
# For compatibility of android-ndk-r9, 4.7 was removed from r9
if [ -d "${NDK_ROOT}/toolchains/arm-linux-androideabi-4.7" ]; then
export NDK_TOOLCHAIN_VERSION=4.7
echo "The Selected NDK toolchain version was 4.7 !"
else
if [ -d "${NDK_ROOT}/toolchains/arm-linux-androideabi-4.8" ]; then
export NDK_TOOLCHAIN_VERSION=4.8
echo "The Selected NDK toolchain version was 4.8 !"
else
echo "Couldn't find the gcc toolchain."
exit 1
fi
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# ... use paths relative to current directory
COCOS2DX_ROOT="$DIR/../../.."
APP_ROOT="$DIR/.."
APP_ANDROID_ROOT="$DIR"
BINDINGS_JS_ROOT="$APP_ROOT/../../cocos/scripting/javascript/script"
echo
echo "Paths"
echo " NDK_ROOT = $NDK_ROOT"
echo " COCOS2DX_ROOT = $COCOS2DX_ROOT"
echo " APP_ROOT = $APP_ROOT"
echo " APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
echo
# Debug
set -x
# make sure assets is exist
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
rm -rf "$APP_ANDROID_ROOT"/assets
fi
mkdir "$APP_ANDROID_ROOT"/assets
mkdir "$APP_ANDROID_ROOT"/assets/res
# copy Resources/* into assets' root
cp -rf "$APP_ROOT"/Resources/* "$APP_ANDROID_ROOT"/assets
# copy bindings/*.js into assets' root
cp -rf "$BINDINGS_JS_ROOT"/* "$APP_ANDROID_ROOT"/assets
echo "Using prebuilt externals"
echo
set -x
"$NDK_ROOT"/ndk-build $PARALLEL_BUILD_FLAG -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos:${COCOS2DX_ROOT}/external" \
NDK_LOG=0 V=0

View File

@ -1,86 +0,0 @@
@echo off
set APPNAME="HelloLua"
set buildexternalsfromsource=
set PARALLEL_BUILD_FLAG=
goto :getopts
:usage
echo Build C/C++ code for %APPNAME% using Android NDK
echo OPTIONS:
echo -s Build externals from source
echo -h this help
pause
exit /b 1
:def
echo "NDK_ROOT not defined. Please define NDK_ROOT in your environment."
pause
exit /b 1
:getopts
set "par=%~1"
if "%par%"=="" (goto :L)
if "%~1"=="-s" set /a buildexternalsfromsource=1
if "%~1"=="-h" goto :usage
shift
goto :getopts
:L
set NDK_ROOT=%NDK_ROOT%
if "%NDK_ROOT%"=="" goto:def
rem check toolchains
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.8 (goto :toolchains48)
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.7 (goto :toolchains47)
if exist %NDK_ROOT%\toolchains\arm-linux-androideabi-4.6 (goto :toolchains46)
echo "Couldn't find the gcc toolchain."
pause
exit /b 1
:toolchains48
set NDK_TOOLCHAIN_VERSION=4.8
goto :InitPath
:toolchains47
set NDK_TOOLCHAIN_VERSION=4.7
goto :InitPath
:toolchains46
set NDK_TOOLCHAIN_VERSION=4.6
:InitPath
set COCOS2DX_ROOT=%~dp0..\..\..
set APP_ROOT=%~dp0..
set APP_ANDROID_ROOT=%~dp0
if "%buildexternalsfromsource%"=="1" (goto :MODULE1) else (goto :MODULE2)
:MODULE1
echo "Building external dependencies from source"
set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%\cocos2dx\platform\third_party\android\source
goto :COPY_RES
:MODULE2
echo "Using prebuilt externals"
set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%\cocos;%COCOS2DX_ROOT%\external
:COPY_RES
echo NDK_ROOT = %NDK_ROOT%
echo COCOS2DX_ROOT=%COCOS2DX_ROOT%
echo APP_ROOT=%APP_ROOT%
echo APP_ANDROID_ROOT=%APP_ANDROID_ROOT%
echo NDK_TOOLCHAIN_VERSION=%NDK_TOOLCHAIN_VERSION%
rem make sure assets is exist
if exist %APP_ANDROID_ROOT%\assets rd /q /s %APP_ANDROID_ROOT%\assets
mkdir %APP_ANDROID_ROOT%\assets
rem copy Resources/* into assets' root
xcopy /e /q /r /y %APP_ROOT%\Resources\* %APP_ANDROID_ROOT%\assets
rem copy common luaScript
xcopy /e /q /r /y %COCOS2DX_ROOT%\cocos\scripting\lua\script\* %APP_ANDROID_ROOT%\assets
call %NDK_ROOT%\ndk-build.cmd NDK_LOG=0 V=0 %*
pause

View File

@ -0,0 +1,104 @@
#!/usr/bin/python
# build_native.py
# Build native codes
import sys
import os, os.path
import shutil
def check_environment_variables():
''' Checking the environment NDK_ROOT, which will be used for building
'''
try:
NDK_ROOT = os.environ['NDK_ROOT']
except Exception:
print "NDK_ROOT not defined. Please define NDK_ROOT in your environment"
sys.exit(1)
return NDK_ROOT
def select_toolchain_version():
'''Because ndk-r8e uses gcc4.6 as default. gcc4.6 doesn't support c++11. So we should select gcc4.7 when
using ndk-r8e. But gcc4.7 is removed in ndk-r9, so we should determine whether gcc4.7 exist.
Conclution:
ndk-r8e -> use gcc4.7
ndk-r9 -> use gcc4.8
'''
ndk_root = check_environment_variables()
if os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.8")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.8'
print "The Selected NDK toolchain version was 4.8 !"
elif os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.7")):
os.environ['NDK_TOOLCHAIN_VERSION'] = '4.7'
print "The Selected NDK toolchain version was 4.7 !"
else:
print "Couldn't find the gcc toolchain."
exit(1)
def do_build(cocos_root, ndk_root, app_android_root):
ndk_path = os.path.join(ndk_root, "ndk-build")
# windows should use ";" to seperate module paths
platform = sys.platform
if platform == 'win32':
ndk_module_path = 'NDK_MODULE_PATH=%s;%s/external;%s/cocos' % (cocos_root, cocos_root, cocos_root)
else:
ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root)
ndk_build_param = sys.argv[1:]
if len(ndk_build_param) == 0:
command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path)
else:
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ''.join(str(e) for e in ndk_build_param), ndk_module_path)
os.system(command)
def copy_files(src, dst):
for item in os.listdir(src):
path = os.path.join(src, item)
# Android can not package the file that ends with ".gz"
if not item.startswith('.') and not item.endswith('.gz') and os.path.isfile(path):
shutil.copy(path, dst)
if os.path.isdir(path):
new_dst = os.path.join(dst, item)
os.mkdir(new_dst)
copy_files(path, new_dst)
def copy_resources(app_android_root):
# remove app_android_root/assets if it exists
assets_dir = os.path.join(app_android_root, "assets")
if os.path.isdir(assets_dir):
shutil.rmtree(assets_dir)
# copy resources
os.mkdir(assets_dir)
resources_dir = os.path.join(app_android_root, "../Resources")
if os.path.isdir(resources_dir):
copy_files(resources_dir, assets_dir)
# lua project should copy lua script
resources_dir = os.path.join(app_android_root, "../../../cocos/scripting/lua/script")
copy_files(resources_dir, assets_dir)
def build():
ndk_root = check_environment_variables()
select_toolchain_version()
current_dir = os.path.dirname(os.path.realpath(__file__))
cocos_root = os.path.join(current_dir, "../../..")
app_android_root = current_dir
copy_resources(app_android_root)
do_build(cocos_root, ndk_root, app_android_root)
# -------------- main --------------
if __name__ == '__main__':
build()

View File

@ -1,102 +0,0 @@
APPNAME="HelloLua"
# options
buildexternalsfromsource=
usage(){
cat << EOF
usage: $0 [options]
Build C/C++ code for $APPNAME using Android NDK
OPTIONS:
-s Build externals from source
-h this help
EOF
}
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
# For compatibility of android-ndk-r9, 4.7 was removed from r9
if [ -d "${NDK_ROOT}/toolchains/arm-linux-androideabi-4.7" ]; then
export NDK_TOOLCHAIN_VERSION=4.7
echo "The Selected NDK toolchain version was 4.7 !"
else
if [ -d "${NDK_ROOT}/toolchains/arm-linux-androideabi-4.8" ]; then
export NDK_TOOLCHAIN_VERSION=4.8
echo "The Selected NDK toolchain version was 4.8 !"
else
echo "Couldn't find the gcc toolchain."
exit 1
fi
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"
# make sure assets is exist
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
rm -rf "$APP_ANDROID_ROOT"/assets
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
# copy common luaScript
for file in "$APP_ROOT"/../../cocos/scripting/lua/script/*
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
if [[ "$buildexternalsfromsource" ]]; then
echo "Building external dependencies from source"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos:${COCOS2DX_ROOT}/external"
else
echo "Using prebuilt externals"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos:${COCOS2DX_ROOT}/external"
fi