diff --git a/build/android-build.py b/build/android-build.py index 34ac6010d9..77189ee5f9 100755 --- a/build/android-build.py +++ b/build/android-build.py @@ -15,8 +15,10 @@ ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES + JSB_SAMPLES def usage(): - print """%s [-n ndk-build-parameter] target. + print """%s [-n ndk-build-parameter] [-p android-platform] [-b build-mode] target. +Valid android-platform are:[10|11|12|13|14|15|16|17] +Valid build-mode are:[debug|release] Valid targets are: [hellocpp|testcpp|simplegame|assetsmanager|hellolua|testlua|cocosdragon |crystalcraze|moonwarriors|testjavascript|watermelonwithme] @@ -33,6 +35,18 @@ def check_environment_variables(): sys.exit(1) return NDK_ROOT + +def check_environment_variables_sdk(): + ''' Checking the environment ANDROID_SDK_ROOT, which will be used for building + ''' + + try: + SDK_ROOT = os.environ['ANDROID_SDK_ROOT'] + except Exception: + print "ANDROID_SDK_ROOT not defined. Please define ANDROID_SDK_ROOT in your environment" + sys.exit(1) + + return SDK_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 @@ -81,7 +95,7 @@ def caculate_built_samples(args): targets = set(targets) return list(targets) -def do_build(cocos_root, ndk_root, app_android_root, ndk_build_param): +def do_build(cocos_root, ndk_root, app_android_root, ndk_build_param,sdk_root,android_platform,build_mode): ndk_path = os.path.join(ndk_root, "ndk-build") @@ -97,7 +111,19 @@ def do_build(cocos_root, ndk_root, app_android_root, ndk_build_param): else: command = '%s -C %s %s %s' % (ndk_path, app_android_root, ndk_build_param, ndk_module_path) if os.system(command) != 0: - raise Exception("Build project [ " + app_android_root + " ] fails!") + raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") + elif android_platform is not None: + sdk_tool_path = os.path.join(sdk_root, "tools/android") + cocoslib_path = os.path.join(cocos_root, "cocos/2d/platform/android/java") + command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path) + if os.system(command) != 0: + raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!") + command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root) + if os.system(command) != 0: + raise Exception("update project [ " + app_android_root + " ] fails!") + buildfile_path = os.path.join(app_android_root, "build.xml") + command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,sdk_root) + os.system(command) def copy_files(src, dst): @@ -169,15 +195,29 @@ def copy_resources(target, app_android_root): resources_dir = os.path.join(app_android_root, "../../../Cpp/TestCpp/Resources") copy_files(resources_dir, assets_dir) -def build_samples(target,ndk_build_param): +def build_samples(target,ndk_build_param,android_platform,build_mode): ndk_root = check_environment_variables() + sdk_root = None select_toolchain_version() build_targets = caculate_built_samples(target) current_dir = os.path.dirname(os.path.realpath(__file__)) cocos_root = os.path.join(current_dir, "..") - + + if android_platform is not None: + sdk_root = check_environment_variables_sdk() + if android_platform.isdigit(): + android_platform = 'android-'+android_platform + else: + print 'please use vaild android platform' + exit(1) + + if build_mode is None: + build_mode = 'debug' + elif build_mode != 'release': + build_mode = 'debug' + app_android_root = '' for target in build_targets: if target == 'hellocpp': @@ -207,7 +247,7 @@ def build_samples(target,ndk_build_param): continue copy_resources(target, app_android_root) - do_build(cocos_root, ndk_root, app_android_root, ndk_build_param) + do_build(cocos_root, ndk_root, app_android_root, ndk_build_param,sdk_root,android_platform,build_mode) # -------------- main -------------- if __name__ == '__main__': @@ -215,13 +255,15 @@ if __name__ == '__main__': #parse the params parser = OptionParser() parser.add_option("-n", "--ndk", dest="ndk_build_param", help='parameter for ndk-build') + parser.add_option("-p", "--platform", dest="android_platform", help='parameter for android-update') + parser.add_option("-b", "--build", dest="build_mode", help='the build mode for java project,debug or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html') (opts, args) = parser.parse_args() if len(args) == 0: usage() else: try: - build_samples(args, opts.ndk_build_param) + build_samples(args, opts.ndk_build_param,opts.android_platform,opts.build_mode) except Exception as e: print e sys.exit(1) diff --git a/tools/travis-scripts/before-install.sh b/tools/travis-scripts/before-install.sh index 79154e4604..acfdd36e12 100755 --- a/tools/travis-scripts/before-install.sh +++ b/tools/travis-scripts/before-install.sh @@ -21,12 +21,12 @@ install_android_ndk() else HOST_NAME="linux" fi - echo "Download android-ndk-r8e-${HOST_NAME}-x86_64.tar.bz2 ..." - curl -O http://dl.google.com/android/ndk/android-ndk-r8e-${HOST_NAME}-x86_64.tar.bz2 - echo "Decompress android-ndk-r8e-${HOST_NAME}-x86_64.tar.bz2 ..." - tar xjf android-ndk-r8e-${HOST_NAME}-x86_64.tar.bz2 + echo "Download android-ndk-r9b-${HOST_NAME}-x86_64.tar.bz2 ..." + curl -O http://dl.google.com/android/ndk/android-ndk-r9b-${HOST_NAME}-x86_64.tar.bz2 + echo "Decompress android-ndk-r9b-${HOST_NAME}-x86_64.tar.bz2 ..." + tar xjf android-ndk-r9b-${HOST_NAME}-x86_64.tar.bz2 # Rename ndk - mv android-ndk-r8e android-ndk + mv android-ndk-r9b android-ndk } install_llvm()