Skip to content

Commit 2ebad9a

Browse files
Bin Zhangminggo
authored andcommitted
Adjust the logic of finding API Level for Android. (#375)
* Adjust the logic of finding API Level for Android. Before Logic: Auto select usable API Level in Android SDK. After Adjust: Only use the API Level configured in project.properties. * Remove the unused code for preview android API Level folders.
1 parent 9644a22 commit 2ebad9a

File tree

1 file changed

+16
-65
lines changed

1 file changed

+16
-65
lines changed

plugins/plugin_compile/build_android.py

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def update_project(self, android_platform):
177177
sdk_tool_path = os.path.join(self.sdk_root, "tools", "android")
178178

179179
# check the android platform
180-
target_str = self.check_android_platform(self.sdk_root, android_platform, manifest_path, False)
180+
target_str = self.check_android_platform(self.sdk_root, android_platform, manifest_path)
181181

182182
# update project
183183
command = "%s update project -t %s -p %s" % (cocos.CMDRunner.convert_path_to_cmd(sdk_tool_path), target_str, manifest_path)
@@ -275,55 +275,22 @@ def update_lib_projects(self, sdk_root, sdk_tool_path, android_platform, propert
275275
abs_lib_path = os.path.join(property_path, lib_path)
276276
abs_lib_path = os.path.normpath(abs_lib_path)
277277
if os.path.isdir(abs_lib_path):
278-
target_str = self.check_android_platform(sdk_root, android_platform, abs_lib_path, True)
278+
target_str = self.check_android_platform(sdk_root, android_platform, abs_lib_path)
279279
command = "%s update lib-project -p %s -t %s" % (cocos.CMDRunner.convert_path_to_cmd(sdk_tool_path), abs_lib_path, target_str)
280280
self._run_cmd(command)
281281

282282
self.update_lib_projects(sdk_root, sdk_tool_path, android_platform, abs_lib_path)
283283

284-
def select_default_android_platform(self, min_api_level):
285-
''' select a default android platform in SDK_ROOT
286-
'''
287-
288-
sdk_root = cocos.check_environment_variable('ANDROID_SDK_ROOT')
289-
platforms_dir = os.path.join(sdk_root, "platforms")
290-
ret_num = -1
291-
ret_platform = ""
292-
if os.path.isdir(platforms_dir):
293-
for dir_name in os.listdir(platforms_dir):
294-
if not os.path.isdir(os.path.join(platforms_dir, dir_name)):
295-
continue
296-
297-
num = self.get_api_level(dir_name, raise_error=False)
298-
if num >= min_api_level:
299-
if ret_num == -1 or ret_num > num:
300-
ret_num = num
301-
ret_platform = dir_name
302-
303-
if ret_num != -1:
304-
return ret_platform
305-
else:
306-
return None
307-
308-
309284
def get_api_level(self, target_str, raise_error=True):
310-
special_targats_info = {
311-
"android-4.2" : 17,
312-
"android-L" : 20
313-
}
314-
315-
if special_targats_info.has_key(target_str):
316-
ret = special_targats_info[target_str]
285+
match = re.match(r'android-(\d+)', target_str)
286+
if match is not None:
287+
ret = int(match.group(1))
317288
else:
318-
match = re.match(r'android-(\d+)', target_str)
319-
if match is not None:
320-
ret = int(match.group(1))
289+
if raise_error:
290+
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_NOT_VALID_AP_FMT', target_str),
291+
cocos.CCPluginError.ERROR_PARSE_FILE)
321292
else:
322-
if raise_error:
323-
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_NOT_VALID_AP_FMT', target_str),
324-
cocos.CCPluginError.ERROR_PARSE_FILE)
325-
else:
326-
ret = -1
293+
ret = -1
327294

328295
return ret
329296

@@ -348,42 +315,26 @@ def get_target_config(self, proj_path):
348315
cocos.CCPluginError.ERROR_PARSE_FILE)
349316

350317
# check the selected android platform
351-
def check_android_platform(self, sdk_root, android_platform, proj_path, auto_select):
318+
def check_android_platform(self, sdk_root, android_platform, proj_path):
352319
ret = android_platform
353320
min_platform = self.get_target_config(proj_path)
354321
if android_platform is None:
355-
# not specified platform, found one
356-
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_AUTO_SELECT_AP'))
357-
ret = self.select_default_android_platform(min_platform)
322+
# not specified platform, use the one in project.properties
323+
ret = 'android-%d' % min_platform
358324
else:
359325
# check whether it's larger than min_platform
360326
select_api_level = self.get_api_level(android_platform)
361327
if select_api_level < min_platform:
362-
if auto_select:
363-
# select one for project
364-
ret = self.select_default_android_platform(min_platform)
365-
else:
366-
# raise error
367-
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_AP_TOO_LOW_FMT',
368-
(proj_path, min_platform, select_api_level)),
369-
cocos.CCPluginError.ERROR_WRONG_ARGS)
370-
371-
if ret is None:
372-
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_AP_NOT_FOUND_FMT',
373-
(proj_path, min_platform)),
374-
cocos.CCPluginError.ERROR_PARSE_FILE)
328+
# raise error
329+
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_AP_TOO_LOW_FMT',
330+
(proj_path, min_platform, select_api_level)),
331+
cocos.CCPluginError.ERROR_WRONG_ARGS)
375332

376333
ret_path = os.path.join(cocos.CMDRunner.convert_path_to_python(sdk_root), "platforms", ret)
377334
if not os.path.isdir(ret_path):
378335
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_NO_AP_IN_SDK_FMT', ret),
379336
cocos.CCPluginError.ERROR_PATH_NOT_FOUND)
380337

381-
special_platforms_info = {
382-
"android-4.2" : "android-17"
383-
}
384-
if special_platforms_info.has_key(ret):
385-
ret = special_platforms_info[ret]
386-
387338
return ret
388339

389340
def ant_build_apk(self, build_mode, custom_step_args):

0 commit comments

Comments
 (0)