mirror of https://github.com/axmolengine/axmol.git
add proceed java compilation and generate apk.
This commit is contained in:
parent
eba059e41e
commit
881d43fe3b
|
@ -15,8 +15,10 @@ ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES + JSB_SAMPLES
|
||||||
|
|
||||||
def usage():
|
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
|
Valid targets are: [hellocpp|testcpp|simplegame|assetsmanager|hellolua|testlua|cocosdragon
|
||||||
|crystalcraze|moonwarriors|testjavascript|watermelonwithme]
|
|crystalcraze|moonwarriors|testjavascript|watermelonwithme]
|
||||||
|
|
||||||
|
@ -34,6 +36,18 @@ def check_environment_variables():
|
||||||
|
|
||||||
return NDK_ROOT
|
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():
|
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
|
'''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.
|
using ndk-r8e. But gcc4.7 is removed in ndk-r9, so we should determine whether gcc4.7 exist.
|
||||||
|
@ -81,7 +95,7 @@ def caculate_built_samples(args):
|
||||||
targets = set(targets)
|
targets = set(targets)
|
||||||
return list(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")
|
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:
|
else:
|
||||||
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ndk_build_param, ndk_module_path)
|
command = '%s -C %s %s %s' % (ndk_path, app_android_root, ndk_build_param, ndk_module_path)
|
||||||
if os.system(command) != 0:
|
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):
|
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")
|
resources_dir = os.path.join(app_android_root, "../../../Cpp/TestCpp/Resources")
|
||||||
copy_files(resources_dir, assets_dir)
|
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()
|
ndk_root = check_environment_variables()
|
||||||
|
sdk_root = None
|
||||||
select_toolchain_version()
|
select_toolchain_version()
|
||||||
build_targets = caculate_built_samples(target)
|
build_targets = caculate_built_samples(target)
|
||||||
|
|
||||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
cocos_root = os.path.join(current_dir, "..")
|
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 = ''
|
app_android_root = ''
|
||||||
for target in build_targets:
|
for target in build_targets:
|
||||||
if target == 'hellocpp':
|
if target == 'hellocpp':
|
||||||
|
@ -207,7 +247,7 @@ def build_samples(target,ndk_build_param):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
copy_resources(target, app_android_root)
|
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 --------------
|
# -------------- main --------------
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -215,13 +255,15 @@ if __name__ == '__main__':
|
||||||
#parse the params
|
#parse the params
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
parser.add_option("-n", "--ndk", dest="ndk_build_param", help='parameter for ndk-build')
|
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()
|
(opts, args) = parser.parse_args()
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
usage()
|
usage()
|
||||||
else:
|
else:
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -21,12 +21,12 @@ install_android_ndk()
|
||||||
else
|
else
|
||||||
HOST_NAME="linux"
|
HOST_NAME="linux"
|
||||||
fi
|
fi
|
||||||
echo "Download 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-r8e-${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-r8e-${HOST_NAME}-x86_64.tar.bz2 ..."
|
echo "Decompress android-ndk-r9b-${HOST_NAME}-x86_64.tar.bz2 ..."
|
||||||
tar xjf android-ndk-r8e-${HOST_NAME}-x86_64.tar.bz2
|
tar xjf android-ndk-r9b-${HOST_NAME}-x86_64.tar.bz2
|
||||||
# Rename ndk
|
# Rename ndk
|
||||||
mv android-ndk-r8e android-ndk
|
mv android-ndk-r9b android-ndk
|
||||||
}
|
}
|
||||||
|
|
||||||
install_llvm()
|
install_llvm()
|
||||||
|
|
Loading…
Reference in New Issue