Skip to content

Commit 958531e

Browse files
drelaptopminggo
authored andcommitted
supporting building release APK without key information
1 parent 1b69aa8 commit 958531e

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

bin/strings.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@
137137
"COMPILE_ARG_GROUP_ANDROID" : "Android Options",
138138
"COMPILE_ARG_AP" : "Specify the Android platform used for building Android apk.",
139139
"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.",
140-
"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'.",
140+
"COMPILE_ARG_APP_ABI" : "Set the APP_ABI of ndk-build.Can be multi value separated with ':'. Sample : --app-abi armeabi-v7a:x86. Default value is 'armeabi-v7a'.",
141141
"COMPILE_ARG_TOOLCHAIN" : "Specify the NDK_TOOLCHAIN of ndk-build.",
142142
"COMPILE_ARG_CPPFLAGS" : "Specify the APP_CPPFLAGS of ndk-build.",
143143
"COMPILE_ARG_NO_APK" : "Not generate the apk file.",
144+
"COMPILE_ARG_NO_SIGN" : "Generate unsigned apk even when release mode.",
144145
"COMPILE_ARG_GROUP_WIN" : "Windows Options",
145146
"COMPILE_ARG_VS" : "Specify the Visual Studio version will be used. Such as: 2015. Default find available version automatically.",
146147
"COMPILE_ARG_GROUP_WEB" : "Web Options",
@@ -240,7 +241,7 @@
240241
"GEN_LIBS_GROUP_WIN" : "Windows Options",
241242
"GEN_LIBS_ARG_VS" : "Specify the Visual Studio version, such as 2015. Default find available version automatically.",
242243
"GEN_LIBS_GROUP_ANDROID" : "Android Options",
243-
"GEN_LIBS_ARG_ABI" : "Set the APP_ABI of ndk-build. Can be multi value separated with ':'. Sample : --app-abi armeabi:x86:mips. Default value is 'armeabi'.",
244+
"GEN_LIBS_ARG_ABI" : "Set the APP_ABI of ndk-build. Can be multi value separated with ':'. Sample : --app-abi armeabi-v7a:x86. Default value is 'armeabi-v7a'.",
244245
"GEN_LIBS_ERROR_WRONG_PATH_FMT" : "%s is not a valid path.",
245246
"GEN_LIBS_ERROR_WRONG_FILE_FMT" : "%s is not a valid config file.",
246247
"GEN_LIBS_ERROR_PARSE_FILE_FMT" : "Parse %s failed.",
@@ -482,10 +483,11 @@
482483
"COMPILE_ARG_GROUP_ANDROID" : "Android 相关参数",
483484
"COMPILE_ARG_AP" : "指定编译 Android 工程所需使用的目标平台。",
484485
"COMPILE_ARG_BUILD_TYPE" : "设置 native code 的编译类型,可选值为 ndk-build|none,默认值为 ndk-build。如果指定为 none,native code 不会被编译。",
485-
"COMPILE_ARG_APP_ABI" : "设置 ndk-build 的 APP_ABI 属性。可以使用 ':' 分隔多个值。示例:--app-abi armeabi:x86:mips。默认值为 'armeabi'。",
486+
"COMPILE_ARG_APP_ABI" : "设置 ndk-build 的 APP_ABI 属性。可以使用 ':' 分隔多个值。示例:--app-abi armeabi-v7a:x86。默认值为 'armeabi-v7a'。",
486487
"COMPILE_ARG_TOOLCHAIN" : "指定 ndk-build 的 NDK_TOOLCHAIN 属性。",
487488
"COMPILE_ARG_CPPFLAGS" : "指定 ndk-build 的 APP_CPPFLAGS 属性。",
488489
"COMPILE_ARG_NO_APK" : "不生成 apk 文件。",
490+
"COMPILE_ARG_NO_SIGN" : "不生成带有签名的 apk 文件。",
489491
"COMPILE_ARG_GROUP_WIN" : "Windows 相关参数",
490492
"COMPILE_ARG_VS" : "指定编译所使用的 Visual Studio 版本。如:2015。默认自动查找可用版本。",
491493
"COMPILE_ARG_GROUP_WEB" : "Web 相关参数",
@@ -585,7 +587,7 @@
585587
"GEN_LIBS_GROUP_WIN" : "Windows 相关参数",
586588
"GEN_LIBS_ARG_VS" : "指定使用的 Visual Studio 版本,例如 2015。默认自动查找可用的版本。",
587589
"GEN_LIBS_GROUP_ANDROID" : "Android 相关参数",
588-
"GEN_LIBS_ARG_ABI" : "设置 ndk-build 的 APP_ABI 属性。可以使用 ':' 分隔多个值。示例:--app-abi armeabi:x86:mips。默认值为 'armeabi'。",
590+
"GEN_LIBS_ARG_ABI" : "设置 ndk-build 的 APP_ABI 属性。可以使用 ':' 分隔多个值。示例:--app-abi armeabi-v7a:x86。默认值为 'armeabi-v7a'。",
589591
"GEN_LIBS_ERROR_WRONG_PATH_FMT" : "%s 不是有效的路径。",
590592
"GEN_LIBS_ERROR_WRONG_FILE_FMT" : "%s 不是有效的配置文件。",
591593
"GEN_LIBS_ERROR_PARSE_FILE_FMT" : "%s 文件解析失败。",
@@ -826,10 +828,11 @@
826828
"COMPILE_ARG_GROUP_ANDROID" : "Android 相關參數",
827829
"COMPILE_ARG_AP" : "指定編譯 Android 工程所需使用的目標平臺。",
828830
"COMPILE_ARG_BUILD_TYPE" : "設置 native code 的編譯類型,可選值為 ndk-build|none,默認值為 ndk-build。如果指定為 none,native code 不會被编译。",
829-
"COMPILE_ARG_APP_ABI" : "設置 ndk-build 的 APP_ABI 屬性。可以使用 ':' 分隔多個值。示例:--app-abi armeabi:x86:mips。默認值為 'armeabi'。",
831+
"COMPILE_ARG_APP_ABI" : "設置 ndk-build 的 APP_ABI 屬性。可以使用 ':' 分隔多個值。示例:--app-abi armeabi-v7a:x86。默認值為 'armeabi-v7a'。",
830832
"COMPILE_ARG_TOOLCHAIN" : "指定 ndk-build 的 NDK_TOOLCHAIN 屬性。",
831833
"COMPILE_ARG_CPPFLAGS" : "指定 ndk-build 的 APP_CPPFLAGS 屬性。",
832834
"COMPILE_ARG_NO_APK" : "不生成 apk 檔。",
835+
"COMPILE_ARG_NO_SIGN" : "不生成帶有簽名的 apk 檔。",
833836
"COMPILE_ARG_GROUP_WIN" : "Windows 相關參數",
834837
"COMPILE_ARG_VS" : "編譯所使用的 Visual Studio 版本。如:2015。默認自動查找可用版本。",
835838
"COMPILE_ARG_GROUP_WEB" : "Web 相關參數",
@@ -929,7 +932,7 @@
929932
"GEN_LIBS_GROUP_WIN" : "Windows 相關參數",
930933
"GEN_LIBS_ARG_VS" : "指定使用的 Visual Studio 版本,例如 2015。默認自動查找可用的版本。",
931934
"GEN_LIBS_GROUP_ANDROID" : "Android 相關參數",
932-
"GEN_LIBS_ARG_ABI" : "設置 ndk-build 的 APP_ABI 屬性。可以使用 ':' 分隔多個值。示例:--app-abi armeabi:x86:mips。默認值為 'armeabi'。",
935+
"GEN_LIBS_ARG_ABI" : "設置 ndk-build 的 APP_ABI 屬性。可以使用 ':' 分隔多個值。示例:--app-abi armeabi-v7a:x86。默認值為 'armeabi-v7a'。",
933936
"GEN_LIBS_ERROR_WRONG_PATH_FMT" : "%s 不是有效的路徑。",
934937
"GEN_LIBS_ERROR_WRONG_FILE_FMT" : "%s 不是有效的配置檔。",
935938
"GEN_LIBS_ERROR_PARSE_FILE_FMT" : "%s 檔解析失敗。",

plugins/plugin_compile/build_android.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def _do_get_build_arch(self, str):
448448

449449
# check if need to build other architecture
450450
build_other_arch = False
451-
other_archs = ('armeabi', 'armeabi-v7a', 'x86') # other arches are not supported
451+
other_archs = ('armeabi-v7a', 'x86') # other arches are not supported
452452
for arch in other_archs:
453453
if str.find(arch) != -1:
454454
build_other_arch = True
@@ -487,7 +487,7 @@ def _get_build_arch(self, param_of_appabi):
487487

488488
return self.LuaBuildArch.UNKNOWN
489489

490-
def do_build_apk(self, mode, no_apk, output_dir, custom_step_args, android_platform, compile_obj):
490+
def do_build_apk(self, mode, no_apk, no_sign, output_dir, custom_step_args, android_platform, compile_obj):
491491
assets_dir = os.path.join(self.app_android_root, "app", "assets")
492492
project_name = None
493493
setting_file = os.path.join(self.app_android_root, 'settings.gradle')
@@ -551,22 +551,27 @@ def do_build_apk(self, mode, no_apk, output_dir, custom_step_args, android_platf
551551

552552
if not no_apk:
553553
# gather the sign info if necessary
554-
if mode == "release" and not self.has_keystore_in_signprops():
555-
self._gather_sign_info()
554+
if not no_sign:
555+
if mode == "release" and not self.has_keystore_in_signprops():
556+
self._gather_sign_info()
556557

557558
# build apk
558559
self.gradle_build_apk(mode, android_platform, compile_obj)
559560

560561
# copy the apk to output dir
561562
if output_dir:
562-
apk_name = '%s-%s.apk' % (project_name, mode)
563+
# support generate unsigned apk
564+
if mode == "release" and no_sign:
565+
apk_name = '%s-%s-unsigned.apk' % (project_name, mode)
566+
else:
567+
apk_name = '%s-%s.apk' % (project_name, mode)
563568
gen_apk_path = os.path.join(gen_apk_folder, apk_name)
564569
if not os.path.exists(output_dir):
565570
os.makedirs(output_dir)
566571
shutil.copy(gen_apk_path, output_dir)
567572
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_MOVE_APK_FMT', output_dir))
568573

569-
if mode == "release":
574+
if mode == "release" and not no_sign:
570575
signed_name = "%s-%s-signed.apk" % (project_name, mode)
571576
apk_path = os.path.join(output_dir, signed_name)
572577
if os.path.exists(apk_path):

plugins/plugin_compile/project_compile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def _add_custom_options(self, parser):
8080
help=MultiLanguage.get_string('COMPILE_ARG_CPPFLAGS'))
8181
group.add_argument("--no-apk", dest="no_apk", action="store_true",
8282
help=MultiLanguage.get_string('COMPILE_ARG_NO_APK'))
83+
group.add_argument("--no-sign", dest="no_sign", action="store_true",
84+
help=MultiLanguage.get_string('COMPILE_ARG_NO_SIGN'))
8385

8486
group = parser.add_argument_group(MultiLanguage.get_string('COMPILE_ARG_GROUP_WIN'))
8587
group.add_argument("--vs", dest="vs_version", type=int,
@@ -132,6 +134,7 @@ def _check_custom_options(self, args):
132134
MultiLanguage.get_string('COMPILE_ERROR_WRONG_BUILD_TYPE_FMT',
133135
available_build_types))
134136
self._no_apk = args.no_apk
137+
self._no_sign = args.no_sign
135138

136139
self.app_abi = None
137140
if args.app_abi:
@@ -534,7 +537,7 @@ def build_android(self):
534537
# build apk
535538
if not self._no_apk:
536539
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_BUILD_APK'))
537-
self.apk_path = builder.do_build_apk(build_mode, self._no_apk, output_dir, self._custom_step_args, self._ap, self)
540+
self.apk_path = builder.do_build_apk(build_mode, self._no_apk, self._no_sign, output_dir, self._custom_step_args, self._ap, self)
538541
self.android_package, self.android_activity = builder.get_apk_info()
539542

540543
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_BUILD_SUCCEED'))

plugins/plugin_generate/gen_libs.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def init(self, args):
135135
self.app_abi = 'armeabi-v7a'
136136
else:
137137
self.app_abi = args.app_abi
138+
self.app_abi_list = self.app_abi.split(":")
138139
self.android_platform = args.android_platform
139140

140141
self.lib_dir = os.path.normpath(os.path.join(self.repo_x, self.cfg_info[LibsCompiler.KEY_LIBS_OUTPUT]))
@@ -346,26 +347,27 @@ def compile_android(self):
346347
elif self.language == 'js':
347348
proj_path = os.path.join(engine_dir, 'tests/js-tests')
348349

349-
build_cmd = "%s compile -s %s -p android --mode %s --app-abi %s" % (cmd_path, proj_path, self.mode, self.app_abi)
350-
if self.android_platform is not None:
351-
build_cmd += ' --ap %s' % self.android_platform
352-
self._run_cmd(build_cmd)
353-
354-
# copy .a to prebuilt dir
355-
ANDROID_A_PATH = "proj.android/app/build/intermediates/ndkBuild/%s/obj/local/%s" % (self.mode, self.app_abi)
356-
if self.language != 'cpp':
357-
ANDROID_A_PATH = 'project/' + ANDROID_A_PATH
358-
359-
android_out_dir = os.path.join(self.lib_dir, "android")
360-
obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
361-
copy_cfg = {
362-
"from": obj_dir,
363-
"to": android_out_dir,
364-
"include": [
365-
"*.a$"
366-
]
367-
}
368-
cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)
350+
for app_abi_item in self.app_abi_list:
351+
build_cmd = "%s compile -s %s -p android --no-sign --mode %s --app-abi %s" % (cmd_path, proj_path, self.mode, app_abi_item)
352+
if self.android_platform is not None:
353+
build_cmd += ' --ap %s' % self.android_platform
354+
self._run_cmd(build_cmd)
355+
356+
# copy .a to prebuilt dir
357+
ANDROID_A_PATH = "proj.android/app/build/intermediates/ndkBuild/%s/obj/local/%s" % (self.mode, app_abi_item)
358+
if self.language != 'cpp':
359+
ANDROID_A_PATH = 'project/' + ANDROID_A_PATH
360+
361+
android_out_dir = os.path.join(self.lib_dir, "android", app_abi_item)
362+
obj_dir = os.path.join(proj_path, ANDROID_A_PATH)
363+
copy_cfg = {
364+
"from": obj_dir,
365+
"to": android_out_dir,
366+
"include": [
367+
"*.a$"
368+
]
369+
}
370+
cocos.copy_files_with_config(copy_cfg, obj_dir, android_out_dir)
369371

370372
if not self.disable_strip:
371373
# strip the android libs

0 commit comments

Comments
 (0)