Skip to content

Commit 0e50ef1

Browse files
author
minggo
authored
remove ant building support (#433)
1 parent 742c0b4 commit 0e50ef1

File tree

2 files changed

+79
-189
lines changed

2 files changed

+79
-189
lines changed

plugins/plugin_compile/build_android.py

Lines changed: 61 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class AndroidBuilder(object):
2727
CFG_KEY_ALIAS = "alias"
2828
CFG_KEY_ALIAS_PASS = "alias_pass"
2929

30-
ANT_KEY_STORE = "key.store"
31-
ANT_KEY_ALIAS = "key.alias"
32-
ANT_KEY_STORE_PASS = "key.store.password"
33-
ANT_KEY_ALIAS_PASS = "key.alias.password"
34-
3530
GRADLE_KEY_STORE = "RELEASE_STORE_FILE"
3631
GRADLE_KEY_ALIAS = "RELEASE_KEY_ALIAS"
3732
GRADLE_KEY_STORE_PASS = "RELEASE_STORE_PASSWORD"
@@ -45,25 +40,20 @@ class AndroidBuilder(object):
4540
GRADLE_PROP_LUA_ENCRYPT_KEY = 'PROP_LUA_ENCRYPT_KEY'
4641
GRADLE_PROP_LUA_ENCRYPT_SIGN = 'PROP_LUA_ENCRYPT_SIGN'
4742

48-
def __init__(self, verbose, app_android_root, no_res, proj_obj, ndk_mode, app_abi, use_studio=False, gradle_support_ndk=False):
43+
def __init__(self, verbose, app_android_root, no_res, proj_obj, ndk_mode, app_abi, gradle_support_ndk=False):
4944
self._verbose = verbose
5045

5146
self.app_android_root = app_android_root
5247
self._no_res = no_res
5348
self._project = proj_obj
54-
self.use_studio = use_studio
5549
self.gradle_support_ndk = gradle_support_ndk
5650
self.app_abi = app_abi
5751
self.ndk_mode = ndk_mode
5852

5953
# check environment variable
60-
if self.use_studio:
61-
self.ant_root = None
62-
self.sign_prop_file = os.path.join(self.app_android_root, 'app', "gradle.properties")
63-
else:
64-
self.ant_root = cocos.check_environment_variable('ANT_ROOT')
65-
self.sign_prop_file = os.path.join(self.app_android_root, "ant.properties")
6654
self.sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
55+
self.ant_root = None
56+
self.sign_prop_file = os.path.join(self.app_android_root, 'app', "gradle.properties")
6757

6858
self._parse_cfg()
6959

@@ -72,16 +62,10 @@ def _run_cmd(self, command, cwd=None):
7262

7363
def _parse_cfg(self):
7464
# get the properties for sign release apk
75-
if self.use_studio:
76-
self.key_store_str = AndroidBuilder.GRADLE_KEY_STORE
77-
self.key_alias_str = AndroidBuilder.GRADLE_KEY_ALIAS
78-
self.key_store_pass_str = AndroidBuilder.GRADLE_KEY_STORE_PASS
79-
self.key_alias_pass_str = AndroidBuilder.GRADLE_KEY_ALIAS_PASS
80-
else:
81-
self.key_store_str = AndroidBuilder.ANT_KEY_STORE
82-
self.key_alias_str = AndroidBuilder.ANT_KEY_ALIAS
83-
self.key_store_pass_str = AndroidBuilder.ANT_KEY_STORE_PASS
84-
self.key_alias_pass_str = AndroidBuilder.ANT_KEY_ALIAS_PASS
65+
self.key_store_str = AndroidBuilder.GRADLE_KEY_STORE
66+
self.key_alias_str = AndroidBuilder.GRADLE_KEY_ALIAS
67+
self.key_store_pass_str = AndroidBuilder.GRADLE_KEY_STORE_PASS
68+
self.key_alias_pass_str = AndroidBuilder.GRADLE_KEY_ALIAS_PASS
8569

8670
if self.gradle_support_ndk:
8771
return
@@ -137,10 +121,7 @@ def _parse_cfg(self):
137121

138122
def has_keystore_in_signprops(self):
139123
keystore = None
140-
if self.use_studio:
141-
pattern = re.compile(r"^RELEASE_STORE_FILE=(.+)")
142-
else:
143-
pattern = re.compile(r"^key\.store=(.+)")
124+
pattern = re.compile(r"^RELEASE_STORE_FILE=(.+)")
144125

145126
try:
146127
file_obj = open(self.sign_prop_file)
@@ -242,49 +223,23 @@ def update_project(self, android_platform):
242223
self._write_local_properties(self.app_android_root)
243224
return
244225

245-
# Android SDK removed android command & ant support from SDK tools 25.3.0
246-
# So, we should check the Android SDK tools version
247-
sdk_tools_folder = os.path.join(self.sdk_root, 'tools')
248-
main_ver, minor_ver = self._get_android_sdk_tools_ver(sdk_tools_folder)
249-
no_ant = False
250-
if main_ver > 25 or (main_ver == 25 and minor_ver >= 3):
251-
no_ant = True
252-
253-
if not self.use_studio and no_ant:
254-
# Tip the message that ant is not supported from Android SDK tools 25.3.0
255-
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_ANT_NOT_SUPPORTED'),
256-
cocos.CCPluginError.ERROR_OTHERS)
257-
258-
if self.use_studio:
259-
manifest_path = os.path.join(self.app_android_root, 'app')
260-
else:
261-
manifest_path = self.app_android_root
226+
manifest_path = os.path.join(self.app_android_root, 'app')
262227

263228
# check the android platform
264229
target_str = self.check_android_platform(self.sdk_root, android_platform, manifest_path)
265230

266-
if no_ant:
267-
# should manually update the project
268-
self._write_local_properties(manifest_path)
269-
self._update_project_properties(manifest_path, target_str)
270-
else:
271-
# update project
272-
sdk_tool_path = os.path.join(sdk_tools_folder, "android")
273-
command = "%s update project -t %s -p %s" % (cocos.CMDRunner.convert_path_to_cmd(sdk_tool_path), target_str, manifest_path)
274-
self._run_cmd(command)
275-
276-
# update lib-projects
277-
self.update_lib_projects(self.sdk_root, sdk_tool_path, android_platform, manifest_path)
278-
279-
if self.use_studio:
280-
# copy the local.properties to the app_android_root
281-
file_name = 'local.properties'
282-
src_path = os.path.normpath(os.path.join(manifest_path, file_name))
283-
dst_path = os.path.normpath(os.path.join(self.app_android_root, file_name))
284-
if src_path != dst_path:
285-
if os.path.isfile(dst_path):
286-
os.remove(dst_path)
287-
shutil.copy(src_path, dst_path)
231+
# should manually update the project
232+
self._write_local_properties(manifest_path)
233+
self._update_project_properties(manifest_path, target_str)
234+
235+
# copy the local.properties to the app_android_root
236+
file_name = 'local.properties'
237+
src_path = os.path.normpath(os.path.join(manifest_path, file_name))
238+
dst_path = os.path.normpath(os.path.join(self.app_android_root, file_name))
239+
if src_path != dst_path:
240+
if os.path.isfile(dst_path):
241+
os.remove(dst_path)
242+
shutil.copy(src_path, dst_path)
288243

289244
def get_toolchain_version(self, ndk_root, compile_obj):
290245
# it should be possible to override the toolchain
@@ -299,10 +254,7 @@ def do_ndk_build(self, ndk_build_param, build_mode, compile_obj):
299254

300255
toolchain_version = self.get_toolchain_version(ndk_root, compile_obj)
301256

302-
if self.use_studio:
303-
ndk_work_dir = os.path.join(self.app_android_root, 'app')
304-
else:
305-
ndk_work_dir = self.app_android_root
257+
ndk_work_dir = os.path.join(self.app_android_root, 'app')
306258
reload(sys)
307259
sys.setdefaultencoding('utf8')
308260
ndk_path = cocos.CMDRunner.convert_path_to_cmd(os.path.join(ndk_root, "ndk-build"))
@@ -402,30 +354,6 @@ def check_android_platform(self, sdk_root, android_platform, proj_path):
402354

403355
return ret
404356

405-
def ant_build_apk(self, build_mode, custom_step_args):
406-
app_android_root = self.app_android_root
407-
408-
# run ant build
409-
ant_path = os.path.join(self.ant_root, 'ant')
410-
buildfile_path = os.path.join(app_android_root, "build.xml")
411-
412-
# generate paramters for custom step
413-
args_ant_copy = custom_step_args.copy()
414-
target_platform = cocos_project.Platforms.ANDROID
415-
416-
# invoke custom step: pre-ant-build
417-
self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_PRE_ANT_BUILD,
418-
target_platform, args_ant_copy)
419-
420-
command = "%s clean %s -f %s -Dsdk.dir=%s" % (cocos.CMDRunner.convert_path_to_cmd(ant_path),
421-
build_mode, buildfile_path,
422-
cocos.CMDRunner.convert_path_to_cmd(self.sdk_root))
423-
self._run_cmd(command)
424-
425-
# invoke custom step: post-ant-build
426-
self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_POST_ANT_BUILD,
427-
target_platform, args_ant_copy)
428-
429357
def gradle_build_apk(self, build_mode, android_platform, compile_obj):
430358
# check the compileSdkVersion & buildToolsVersion
431359
check_file = os.path.join(self.app_android_root, 'app', 'build.gradle')
@@ -547,10 +475,7 @@ def _get_build_type(self, param_of_appabi):
547475
return self._do_get_build_type(param_of_appabi)
548476

549477
# get build type from Application.mk
550-
if self.use_studio:
551-
applicationmk_path = os.path.join(self.app_android_root, "app/jni/Application.mk")
552-
else:
553-
applicationmk_path = os.path.join(self.app_android_root, "jni/Application.mk")
478+
applicationmk_path = os.path.join(self.app_android_root, "app/jni/Application.mk")
554479
with open(applicationmk_path) as f:
555480
for line in f:
556481
if line.find('APP_ABI') == -1:
@@ -562,32 +487,27 @@ def _get_build_type(self, param_of_appabi):
562487
return self.LuaBuildType.UNKNOWN
563488

564489
def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android_platform, compile_obj):
565-
if self.use_studio:
566-
assets_dir = os.path.join(self.app_android_root, "app", "assets")
567-
project_name = None
568-
setting_file = os.path.join(self.app_android_root, 'settings.gradle')
569-
if os.path.isfile(setting_file):
570-
# get project name from settings.gradle
571-
f = open(setting_file)
572-
lines = f.readlines()
573-
f.close()
574-
575-
pattern = r"project\(':(.*)'\)\.projectDir[ \t]*=[ \t]*new[ \t]*File\(settingsDir, 'app'\)"
576-
for line in lines:
577-
line_str = line.strip()
578-
match = re.match(pattern, line_str)
579-
if match:
580-
project_name = match.group(1)
581-
break
582-
583-
if project_name is None:
584-
# use default project name
585-
project_name = 'app'
586-
gen_apk_folder = os.path.join(self.app_android_root, 'app/build/outputs/apk', build_mode)
587-
else:
588-
assets_dir = os.path.join(self.app_android_root, "assets")
589-
project_name = self._xml_attr(self.app_android_root, 'build.xml', 'project', 'name')
590-
gen_apk_folder = os.path.join(self.app_android_root, 'bin')
490+
assets_dir = os.path.join(self.app_android_root, "app", "assets")
491+
project_name = None
492+
setting_file = os.path.join(self.app_android_root, 'settings.gradle')
493+
if os.path.isfile(setting_file):
494+
# get project name from settings.gradle
495+
f = open(setting_file)
496+
lines = f.readlines()
497+
f.close()
498+
499+
pattern = r"project\(':(.*)'\)\.projectDir[ \t]*=[ \t]*new[ \t]*File\(settingsDir, 'app'\)"
500+
for line in lines:
501+
line_str = line.strip()
502+
match = re.match(pattern, line_str)
503+
if match:
504+
project_name = match.group(1)
505+
break
506+
507+
if project_name is None:
508+
# use default project name
509+
project_name = 'app'
510+
gen_apk_folder = os.path.join(self.app_android_root, 'app/build/outputs/apk', build_mode)
591511

592512
# gradle supports copy assets & compile scripts from engine 3.15
593513
if not self.gradle_support_ndk:
@@ -634,10 +554,7 @@ def do_build_apk(self, build_mode, no_apk, output_dir, custom_step_args, android
634554
self._gather_sign_info()
635555

636556
# build apk
637-
if self.use_studio:
638-
self.gradle_build_apk(build_mode, android_platform, compile_obj)
639-
else:
640-
self.ant_build_apk(build_mode, custom_step_args)
557+
self.gradle_build_apk(build_mode, android_platform, compile_obj)
641558

642559
# copy the apk to output dir
643560
if output_dir:
@@ -731,26 +648,22 @@ def _copy_resources(self, custom_step_args, assets_dir):
731648
self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_POST_COPY_ASSETS, target_platform, cur_custom_step_args)
732649

733650
def get_apk_info(self):
734-
if self.use_studio:
735-
manifest_path = os.path.join(self.app_android_root, 'app')
736-
gradle_cfg_path = os.path.join(manifest_path, 'build.gradle')
737-
package = None
738-
if os.path.isfile(gradle_cfg_path):
739-
# get package name from build.gradle
740-
f = open(gradle_cfg_path)
741-
for line in f.readlines():
742-
line_str = line.strip()
743-
pattern = r'applicationId[ \t]+"(.*)"'
744-
match = re.match(pattern, line_str)
745-
if match:
746-
package = match.group(1)
747-
break
748-
749-
if package is None:
750-
# get package name from AndroidManifest.xml
751-
package = self._xml_attr(manifest_path, 'AndroidManifest.xml', 'manifest', 'package')
752-
else:
753-
manifest_path = self.app_android_root
651+
manifest_path = os.path.join(self.app_android_root, 'app')
652+
gradle_cfg_path = os.path.join(manifest_path, 'build.gradle')
653+
package = None
654+
if os.path.isfile(gradle_cfg_path):
655+
# get package name from build.gradle
656+
f = open(gradle_cfg_path)
657+
for line in f.readlines():
658+
line_str = line.strip()
659+
pattern = r'applicationId[ \t]+"(.*)"'
660+
match = re.match(pattern, line_str)
661+
if match:
662+
package = match.group(1)
663+
break
664+
665+
if package is None:
666+
# get package name from AndroidManifest.xml
754667
package = self._xml_attr(manifest_path, 'AndroidManifest.xml', 'manifest', 'package')
755668

756669
activity_name = self._xml_attr(manifest_path, 'AndroidManifest.xml', 'activity', 'android:name')

plugins/plugin_compile/project_compile.py

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -470,51 +470,30 @@ def build_android(self):
470470
output_dir = self._output_dir
471471

472472
# get the android project path
473-
# if both proj.android & proj.android-studio existed, select the project path by --studio argument
474-
# else, use the existed one.
475473
cfg_obj = self._platforms.get_current_config()
476-
proj_android_path = cfg_obj.proj_path
477-
proj_studio_path = cfg_obj.studio_path
478-
project_android_dir = None
479-
using_studio = False
480-
if self.is_valid_path(proj_android_path) and self.is_valid_path(proj_studio_path):
481-
if self.use_studio:
482-
project_android_dir = proj_studio_path
483-
using_studio = True
484-
else:
485-
project_android_dir = proj_android_path
486-
using_studio = False
487-
elif self.is_valid_path(proj_android_path):
488-
project_android_dir = proj_android_path
489-
using_studio = False
490-
elif self.is_valid_path(proj_studio_path):
491-
project_android_dir = proj_studio_path
492-
using_studio = True
493-
494-
if using_studio:
495-
ide_name = 'Android Studio'
496-
else:
497-
ide_name = 'Eclipse'
474+
project_android_dir = cfg_obj.proj_path
475+
476+
477+
ide_name = 'Android Studio'
498478
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_ANDROID_PROJPATH_FMT', (ide_name, project_android_dir)))
499479

500480
# Check whether the gradle of the project is support ndk or not
501-
gradle_support_ndk = False
502-
if using_studio:
503-
# Get the engine version of the project
504-
engine_version_num = self.get_engine_version_num()
505-
if engine_version_num is None:
506-
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_UNKNOWN_ENGINE_VERSION'))
507-
508-
# Gradle supports NDK build from engine 3.15
509-
main_ver = engine_version_num[0]
510-
minor_ver = engine_version_num[1]
511-
if main_ver > 3 or (main_ver == 3 and minor_ver >= 15):
512-
gradle_support_ndk = True
481+
# Get the engine version of the project
482+
engine_version_num = self.get_engine_version_num()
483+
if engine_version_num is None:
484+
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_UNKNOWN_ENGINE_VERSION'))
485+
486+
# Gradle supports NDK build from engine 3.15
487+
main_ver = engine_version_num[0]
488+
minor_ver = engine_version_num[1]
489+
if main_ver > 3 or (main_ver == 3 and minor_ver >= 15):
490+
gradle_support_ndk = True
491+
513492

514493
from build_android import AndroidBuilder
515494
builder = AndroidBuilder(self._verbose, project_android_dir,
516495
self._no_res, self._project, self._ndk_mode,
517-
self.app_abi, using_studio, gradle_support_ndk)
496+
self.app_abi, gradle_support_ndk)
518497

519498
args_ndk_copy = self._custom_step_args.copy()
520499
target_platform = self._platforms.get_current_platform()
@@ -541,10 +520,8 @@ def build_android(self):
541520
self._project.invoke_custom_step_script(cocos_project.Project.CUSTOM_STEP_PRE_NDK_BUILD, target_platform, args_ndk_copy)
542521

543522
modify_mk = False
544-
if using_studio:
545-
app_mk = os.path.join(project_android_dir, "app/jni/Application.mk")
546-
else:
547-
app_mk = os.path.join(project_android_dir, "jni/Application.mk")
523+
app_mk = os.path.join(project_android_dir, "app/jni/Application.mk")
524+
548525
mk_content = None
549526
if self.cppflags and os.path.exists(app_mk):
550527
# record the content of Application.mk

0 commit comments

Comments
 (0)