Skip to content

Commit e19b816

Browse files
drelaptopminggo
authored andcommitted
adjust cocos CLI for cocos2dx 3.17 (#438)
* fix run on ios simulator error on xcode9 * add i386 to valid archs * cmd support cmake build for android * cocos cmd didn't support android-cmake yet * remove useless android-studio option * fix a typo error * adapt linux cmake build path * adapt linux cmake result dir * adapt lua cmake file dir * improve var name mode(debug/release) type(ndk-build/none) * improve var name, arch(i386 x64 arm64...) * update method of run simulator for xcode9
1 parent 03d1f8d commit e19b816

File tree

5 files changed

+71
-72
lines changed

5 files changed

+71
-72
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ v*-console-*.zip
6161
# Ignore the files generated by toexec/build-console
6262
toexec/output/
6363
toexec/build/
64+
65+
#vscode files
66+
67+
.vscode/

bin/strings.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,10 @@
136136
"COMPILE_ARG_OUTPUT" : "Specify the output directory.",
137137
"COMPILE_ARG_GROUP_ANDROID" : "Android Options",
138138
"COMPILE_ARG_AP" : "Specify the Android platform used for building Android apk.",
139-
"COMPILE_ARG_NDK_MODE" : "Set the compiling mode of ndk-build, should be debug|release|none, native code will not be compiled when the value is none. Default is same value with '-m'.",
139+
"COMPILE_ARG_BUILD_TYPE" : "Set the compiling type of native code, should be ndk-build|none, default is ndk-build. Native code will not be compiled when the value is none.",
140140
"COMPILE_ARG_APP_ABI" : "Set the APP_ABI of ndk-build.Can be multi value separated with ':'. Sample : --app-abi armeabi:x86:mips. Default value is 'armeabi'.",
141141
"COMPILE_ARG_TOOLCHAIN" : "Specify the NDK_TOOLCHAIN of ndk-build.",
142142
"COMPILE_ARG_CPPFLAGS" : "Specify the APP_CPPFLAGS of ndk-build.",
143-
"COMPILE_ARG_STUDIO" : "Use the Android Studio project for Android platform.",
144143
"COMPILE_ARG_NO_APK" : "Not generate the apk file.",
145144
"COMPILE_ARG_GROUP_WIN" : "Windows Options",
146145
"COMPILE_ARG_VS" : "Specify the Visual Studio version will be used. Such as: 2013. Default find available version automatically.",
@@ -179,7 +178,7 @@
179178
"COMPILE_INFO_REQUIRED_VS_FMT" : "Required VS version : %s",
180179
"COMPILE_INFO_USE_COCOAPODS" : "CocoaPods detected: use xcworkspace for build",
181180
"COMPILE_ERROR_WRONG_MODE_FMT" : "Value of '-m' should be one of %s.",
182-
"COMPILE_ERROR_WRONG_NDK_MODE_FMT" : "Value of '--ndk-mode' should be one of %s.",
181+
"COMPILE_ERROR_WRONG_BUILD_TYPE_FMT" : "Value of '--build-type' should be one of %s.",
183182
"COMPILE_ERROR_WRONG_VS_VER_FMT" : "VS %d is not supported.",
184183
"COMPILE_ERROR_LOW_VS_VER" : "Version of VS is too low.",
185184
"COMPILE_ERROR_MSDBUILD_NOT_FOUND" : "MSBuild is not found.",
@@ -215,7 +214,7 @@
215214
"COMPILE_WARNING_COMPILE_SDK_FMT" : "The value of compileSdkVersion is %s in file build.gradle, but %s is not found.",
216215
"COMPILE_WARNING_BUILD_TOOLS_FMT" : "The value of buildToolsVersion is %s in file build.gradle, but %s is not found.",
217216
"COMPILE_INFO_NDK_TOOLCHAIN_VER_FMT" : "NDK_TOOLCHAIN_VERSION: %s",
218-
"COMPILE_INFO_NDK_MODE" : "NDK build mode: %s",
217+
"COMPILE_INFO_NDK_BUILD_TYPE" : "NDK build type: %s",
219218
"COMPILE_INFO_AUTO_SELECT_AP" : "Android platform not specified, searching a default one...",
220219
"COMPILE_INFO_MOVE_APK_FMT" : "Move apk to %s",
221220
"COMPILE_INFO_NOT_A_FILE" : "The string inputed is not a file!",
@@ -482,11 +481,10 @@
482481
"COMPILE_ARG_OUTPUT" : "指定输出文件的路径。",
483482
"COMPILE_ARG_GROUP_ANDROID" : "Android 相关参数",
484483
"COMPILE_ARG_AP" : "指定编译 Android 工程所需使用的目标平台。",
485-
"COMPILE_ARG_NDK_MODE" : "设置 ndk-build 的模式,可选值为 debug|release|none,如果指定为 none,ndk-build 不会被调用。默认值与 '-m' 参数值相同",
484+
"COMPILE_ARG_BUILD_TYPE" : "设置 native code 的编译类型,可选值为 ndk-build|none,默认值为 ndk-build。如果指定为 none,native code 不会被编译",
486485
"COMPILE_ARG_APP_ABI" : "设置 ndk-build 的 APP_ABI 属性。可以使用 ':' 分隔多个值。示例:--app-abi armeabi:x86:mips。默认值为 'armeabi'。",
487486
"COMPILE_ARG_TOOLCHAIN" : "指定 ndk-build 的 NDK_TOOLCHAIN 属性。",
488487
"COMPILE_ARG_CPPFLAGS" : "指定 ndk-build 的 APP_CPPFLAGS 属性。",
489-
"COMPILE_ARG_STUDIO" : "使用 Android Studio 工程来编译 Android 平台。",
490488
"COMPILE_ARG_NO_APK" : "不生成 apk 文件。",
491489
"COMPILE_ARG_GROUP_WIN" : "Windows 相关参数",
492490
"COMPILE_ARG_VS" : "指定编译所使用的 Visual Studio 版本。如:2013。默认自动查找可用版本。",
@@ -525,7 +523,7 @@
525523
"COMPILE_INFO_REQUIRED_VS_FMT" : "要求的 VS 版本:%s",
526524
"COMPILE_INFO_USE_COCOAPODS" : "检测到 CocoaPods:使用 xcworkspace 进行编译。",
527525
"COMPILE_ERROR_WRONG_MODE_FMT" : "'-m' 参数取值范围:%s。",
528-
"COMPILE_ERROR_WRONG_NDK_MODE_FMT" : "'--ndk-mode' 参数取值范围:%s。",
526+
"COMPILE_ERROR_WRONG_BUILD_TYPE_FMT" : "'--build-type' 参数取值范围:%s。",
529527
"COMPILE_ERROR_WRONG_VS_VER_FMT" : "不支持 VS %d。",
530528
"COMPILE_ERROR_LOW_VS_VER" : "VS 版本过低。",
531529
"COMPILE_ERROR_MSDBUILD_NOT_FOUND" : "未找到 MSBuild 工具。",
@@ -561,7 +559,7 @@
561559
"COMPILE_WARNING_COMPILE_SDK_FMT" : "build.gradle 文件中 compileSdkVersion 的值为 %s,但是文件夹 %s 不存在。",
562560
"COMPILE_WARNING_BUILD_TOOLS_FMT" : "build.gradle 文件中 buildToolsVersion 的值为 %s,但是文件夹 %s 不存在。",
563561
"COMPILE_INFO_NDK_TOOLCHAIN_VER_FMT" : "NDK_TOOLCHAIN_VERSION: %s",
564-
"COMPILE_INFO_NDK_MODE" : "NDK 编译模式:%s",
562+
"COMPILE_INFO_NDK_BUILD_TYPE" : "NDK 编译类型:%s",
565563
"COMPILE_INFO_AUTO_SELECT_AP" : "未指定 Android 目标平台版本,自动查找一个可用版本...",
566564
"COMPILE_INFO_MOVE_APK_FMT" : "正在移动 apk 文件 %s",
567565
"COMPILE_INFO_NOT_A_FILE" : "输入的路径不是一个有效的文件。",
@@ -827,11 +825,10 @@
827825
"COMPILE_ARG_OUTPUT" : "指定輸出檔案的路徑。",
828826
"COMPILE_ARG_GROUP_ANDROID" : "Android 相關參數",
829827
"COMPILE_ARG_AP" : "指定編譯 Android 工程所需使用的目標平臺。",
830-
"COMPILE_ARG_NDK_MODE" : "設置 ndk-build 的模式,可選值為 debug|release|none,如果指定為 none,ndk-build 不會被調用。默認值與 '-m' 參數值相同",
828+
"COMPILE_ARG_BUILD_TYPE" : "設置 native code 的編譯類型,可選值為 ndk-build|none,默認值為 ndk-build。如果指定為 none,native code 不會被编译",
831829
"COMPILE_ARG_APP_ABI" : "設置 ndk-build 的 APP_ABI 屬性。可以使用 ':' 分隔多個值。示例:--app-abi armeabi:x86:mips。默認值為 'armeabi'。",
832830
"COMPILE_ARG_TOOLCHAIN" : "指定 ndk-build 的 NDK_TOOLCHAIN 屬性。",
833831
"COMPILE_ARG_CPPFLAGS" : "指定 ndk-build 的 APP_CPPFLAGS 屬性。",
834-
"COMPILE_ARG_STUDIO" : "使用 Android Studio 工程來編譯 Android 平臺。",
835832
"COMPILE_ARG_NO_APK" : "不生成 apk 檔。",
836833
"COMPILE_ARG_GROUP_WIN" : "Windows 相關參數",
837834
"COMPILE_ARG_VS" : "編譯所使用的 Visual Studio 版本。如:2013。默認自動查找可用版本。",
@@ -870,7 +867,7 @@
870867
"COMPILE_INFO_REQUIRED_VS_FMT" : "要求的 VS 版本:%s",
871868
"COMPILE_INFO_USE_COCOAPODS" : "檢測到 CocoaPods:使用 xcworkspace 进行编译。",
872869
"COMPILE_ERROR_WRONG_MODE_FMT" : "'-m' 參數取值範圍:%s。",
873-
"COMPILE_ERROR_WRONG_NDK_MODE_FMT" : "'--ndk-mode' 參數取值範圍:%s。",
870+
"COMPILE_ERROR_WRONG_BUILD_TYPE_FMT" : "'--build-type' 參數取值範圍:%s。",
874871
"COMPILE_ERROR_WRONG_VS_VER_FMT" : "不支持 VS %d。",
875872
"COMPILE_ERROR_LOW_VS_VER" : "VS 版本過低。",
876873
"COMPILE_ERROR_MSDBUILD_NOT_FOUND" : "未找到 MSBuild 工具。",
@@ -906,7 +903,7 @@
906903
"COMPILE_WARNING_COMPILE_SDK_FMT" : "build.gradle 檔案中 compileSdkVersion 的值為 %s,但是檔案夾 %s 不存在。",
907904
"COMPILE_WARNING_BUILD_TOOLS_FMT" : "build.gradle 檔案中 buildToolsVersion 的值為 %s,但是檔案夾 %s 不存在。",
908905
"COMPILE_INFO_NDK_TOOLCHAIN_VER_FMT" : "NDK_TOOLCHAIN_VERSION: %s",
909-
"COMPILE_INFO_NDK_MODE" : "NDK 編譯模式:%s",
906+
"COMPILE_INFO_NDK_BUILD_TYPE" : "NDK 編譯類型:%s",
910907
"COMPILE_INFO_AUTO_SELECT_AP" : "未指定 Android 目標平臺版本,自動查找一個可用版本...",
911908
"COMPILE_INFO_MOVE_APK_FMT" : "正在移動 apk 檔案 %s",
912909
"COMPILE_INFO_NOT_A_FILE" : "輸入的路徑不是一個有效的檔案。",

plugins/plugin_compile/build_android.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,23 @@ class AndroidBuilder(object):
3333
GRADLE_KEY_ALIAS_PASS = "RELEASE_KEY_PASSWORD"
3434

3535
GRADLE_PROP_TARGET_VERSION = 'PROP_TARGET_SDK_VERSION'
36-
GRADLE_PROP_NDK_MODE = 'PROP_NDK_MODE'
36+
GRADLE_PROP_BUILD_TYPE = 'PROP_BUILD_TYPE'
3737
GRADLE_PROP_APP_ABI = 'PROP_APP_ABI'
3838
GRADLE_PROP_COMPILE_SCRIPT = 'PROP_COMPILE_SCRIPT'
3939
GRADLE_PROP_LUA_ENCRYPT = 'PROP_LUA_ENCRYPT'
4040
GRADLE_PROP_LUA_ENCRYPT_KEY = 'PROP_LUA_ENCRYPT_KEY'
4141
GRADLE_PROP_LUA_ENCRYPT_SIGN = 'PROP_LUA_ENCRYPT_SIGN'
4242

43-
def __init__(self, verbose, app_android_root, no_res, proj_obj, ndk_mode, app_abi, gradle_support_ndk=False):
43+
def __init__(self, verbose, app_android_root, no_res, proj_obj, mode, build_type, app_abi, gradle_support_ndk=False):
4444
self._verbose = verbose
4545

4646
self.app_android_root = app_android_root
4747
self._no_res = no_res
4848
self._project = proj_obj
4949
self.gradle_support_ndk = gradle_support_ndk
5050
self.app_abi = app_abi
51-
self.ndk_mode = ndk_mode
51+
self.mode = mode
52+
self.build_type = build_type
5253

5354
# check environment variable
5455
self.sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
@@ -248,8 +249,8 @@ def get_toolchain_version(self, ndk_root, compile_obj):
248249
return '4.9'
249250

250251

251-
def do_ndk_build(self, ndk_build_param, build_mode, compile_obj):
252-
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_NDK_MODE', build_mode))
252+
def do_ndk_build(self, ndk_build_param, mode, build_type, compile_obj):
253+
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_NDK_BUILD_TYPE', build_type))
253254
ndk_root = cocos.check_environment_variable('NDK_ROOT')
254255

255256
toolchain_version = self.get_toolchain_version(ndk_root, compile_obj)
@@ -274,7 +275,7 @@ def do_ndk_build(self, ndk_build_param, build_mode, compile_obj):
274275

275276
ndk_build_cmd = '%s NDK_TOOLCHAIN_VERSION=%s' % (ndk_build_cmd, toolchain_version)
276277

277-
if build_mode == 'debug':
278+
if mode == 'debug':
278279
ndk_build_cmd = '%s NDK_DEBUG=1' % ndk_build_cmd
279280

280281
self._run_cmd(ndk_build_cmd)
@@ -354,7 +355,7 @@ def check_android_platform(self, sdk_root, android_platform, proj_path):
354355

355356
return ret
356357

357-
def gradle_build_apk(self, build_mode, android_platform, compile_obj):
358+
def gradle_build_apk(self, mode, android_platform, compile_obj):
358359
# check the compileSdkVersion & buildToolsVersion
359360
check_file = os.path.join(self.app_android_root, 'app', 'build.gradle')
360361
f = open(check_file)
@@ -400,12 +401,12 @@ def gradle_build_apk(self, build_mode, android_platform, compile_obj):
400401
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_GRALEW_NOT_EXIST_FMT', gradle_path),
401402
cocos.CCPluginError.ERROR_PATH_NOT_FOUND)
402403

403-
mode_str = 'Debug' if build_mode == 'debug' else 'Release'
404+
mode_str = 'Debug' if mode == 'debug' else 'Release'
404405
cmd = '"%s" --parallel --info assemble%s' % (gradle_path, mode_str)
405406

406407
if self.gradle_support_ndk:
407408
add_props = {
408-
AndroidBuilder.GRADLE_PROP_NDK_MODE: self.ndk_mode
409+
AndroidBuilder.GRADLE_PROP_BUILD_TYPE: self.build_type
409410
}
410411
if android_platform:
411412
ret = self.check_android_platform(self.sdk_root, android_platform, None)
@@ -434,13 +435,13 @@ def gradle_build_apk(self, build_mode, android_platform, compile_obj):
434435

435436
self._run_cmd(cmd, cwd=self.app_android_root)
436437

437-
class LuaBuildType:
438+
class LuaBuildArch:
438439
UNKNOWN = -1
439440
ONLY_BUILD_64BIT = 1
440441
ONLY_BUILD_32BIT = 2
441442
BUILD_32BIT_AND_64BIT = 3
442443

443-
def _do_get_build_type(self, str):
444+
def _do_get_build_arch(self, str):
444445
# remove the '#' and the contents after it
445446
str = str.split('#')[0]
446447
build_64bit = str.find('arm64-v8a') != -1
@@ -457,36 +458,36 @@ def _do_get_build_type(self, str):
457458
if build_64bit:
458459
if build_other_arch:
459460
print 'build 64bit and 32bit'
460-
return self.LuaBuildType.BUILD_32BIT_AND_64BIT
461+
return self.LuaBuildArch.BUILD_32BIT_AND_64BIT
461462
else:
462463
print 'only build 64bit'
463-
return self.LuaBuildType.ONLY_BUILD_64BIT
464+
return self.LuaBuildArch.ONLY_BUILD_64BIT
464465
else:
465466
print 'only build 32bit'
466-
return self.LuaBuildType.ONLY_BUILD_32BIT
467+
return self.LuaBuildArch.ONLY_BUILD_32BIT
467468

468-
return self.LuaBuildType.UNKNOWN
469+
return self.LuaBuildArch.UNKNOWN
469470

470471
# check if arm64-v8a is set in Application.mk
471-
def _get_build_type(self, param_of_appabi):
472+
def _get_build_arch(self, param_of_appabi):
472473

473474
# get build type from parameter
474475
if param_of_appabi:
475-
return self._do_get_build_type(param_of_appabi)
476+
return self._do_get_build_arch(param_of_appabi)
476477

477478
# get build type from Application.mk
478479
applicationmk_path = os.path.join(self.app_android_root, "app/jni/Application.mk")
479480
with open(applicationmk_path) as f:
480481
for line in f:
481482
if line.find('APP_ABI') == -1:
482483
continue
483-
build_type = self._do_get_build_type(line)
484-
if build_type != self.LuaBuildType.UNKNOWN:
485-
return build_type
484+
build_arch = self._do_get_build_arch(line)
485+
if build_arch != self.LuaBuildArch.UNKNOWN:
486+
return build_arch
486487

487-
return self.LuaBuildType.UNKNOWN
488+
return self.LuaBuildArch.UNKNOWN
488489

489-
def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android_platform, compile_obj):
490+
def do_build_apk(self, mode, no_apk, output_dir, custom_step_args, android_platform, compile_obj):
490491
assets_dir = os.path.join(self.app_android_root, "app", "assets")
491492
project_name = None
492493
setting_file = os.path.join(self.app_android_root, 'settings.gradle')
@@ -507,7 +508,7 @@ def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android
507508
if project_name is None:
508509
# use default project name
509510
project_name = 'app'
510-
gen_apk_folder = os.path.join(self.app_android_root, 'app/build/outputs/apk', build_mode)
511+
gen_apk_folder = os.path.join(self.app_android_root, 'app/build/outputs/apk', mode)
511512

512513
# gradle supports copy assets & compile scripts from engine 3.15
513514
if not self.gradle_support_ndk:
@@ -517,10 +518,10 @@ def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android
517518
# check the project config & compile the script files
518519
if self._project._is_lua_project():
519520
src_dir = os.path.join(assets_dir, 'src')
520-
build_type = self._get_build_type(compile_obj.app_abi)
521+
build_arch = self._get_build_arch(compile_obj.app_abi)
521522

522523
# only build 64bit
523-
if build_type == self.LuaBuildType.ONLY_BUILD_64BIT:
524+
if build_arch == self.LuaBuildArch.ONLY_BUILD_64BIT:
524525
dst_dir = os.path.join(assets_dir, 'src/64bit')
525526
is_compiled = compile_obj.compile_lua_scripts(src_dir, dst_dir, True)
526527
if is_compiled:
@@ -529,19 +530,19 @@ def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android
529530
shutil.rmtree(os.path.join(src_dir, 'cocos'))
530531

531532
# only build 32bit
532-
if build_type == self.LuaBuildType.ONLY_BUILD_32BIT:
533+
if build_arch == self.LuaBuildArch.ONLY_BUILD_32BIT:
533534
# build 32-bit bytecode
534535
compile_obj.compile_lua_scripts(src_dir, src_dir, False)
535536

536537
# build 32bit and 64bit
537-
if build_type == self.LuaBuildType.BUILD_32BIT_AND_64BIT:
538+
if build_arch == self.LuaBuildArch.BUILD_32BIT_AND_64BIT:
538539
# build 64-bit bytecode
539540
dst_dir = os.path.join(assets_dir, 'src/64bit')
540541
compile_obj.compile_lua_scripts(src_dir, dst_dir, True)
541542
# build 32-bit bytecode
542543
compile_obj.compile_lua_scripts(src_dir, src_dir, False)
543544

544-
if build_type == self.LuaBuildType.UNKNOWN:
545+
if build_arch == self.LuaBuildArch.UNKNOWN:
545546
# haven't set APP_ABI in parameter and Application.mk, default build 32bit
546547
compile_obj.compile_lua_scripts(src_dir, src_dir, False)
547548

@@ -550,23 +551,23 @@ def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android
550551

551552
if not no_apk:
552553
# gather the sign info if necessary
553-
if build_mode == "release" and not self.has_keystore_in_signprops():
554+
if mode == "release" and not self.has_keystore_in_signprops():
554555
self._gather_sign_info()
555556

556557
# build apk
557-
self.gradle_build_apk(build_mode, android_platform, compile_obj)
558+
self.gradle_build_apk(mode, android_platform, compile_obj)
558559

559560
# copy the apk to output dir
560561
if output_dir:
561-
apk_name = '%s-%s.apk' % (project_name, build_mode)
562+
apk_name = '%s-%s.apk' % (project_name, mode)
562563
gen_apk_path = os.path.join(gen_apk_folder, apk_name)
563564
if not os.path.exists(output_dir):
564565
os.makedirs(output_dir)
565566
shutil.copy(gen_apk_path, output_dir)
566567
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_MOVE_APK_FMT', output_dir))
567568

568-
if build_mode == "release":
569-
signed_name = "%s-%s-signed.apk" % (project_name, build_mode)
569+
if mode == "release":
570+
signed_name = "%s-%s-signed.apk" % (project_name, mode)
570571
apk_path = os.path.join(output_dir, signed_name)
571572
if os.path.exists(apk_path):
572573
os.remove(apk_path)
@@ -586,10 +587,7 @@ def _gather_sign_info(self):
586587
inputed = self._get_user_input(MultiLanguage.get_string('COMPILE_TIP_INPUT_KEYSTORE'))
587588
inputed = inputed.strip()
588589
if not os.path.isabs(inputed):
589-
if self.use_studio:
590-
start_path = os.path.join(self.app_android_root, 'app')
591-
else:
592-
start_path = self.app_android_root
590+
start_path = os.path.join(self.app_android_root, 'app')
593591
abs_path = os.path.join(start_path, inputed)
594592
else:
595593
abs_path = inputed

0 commit comments

Comments
 (0)