|
27 | 27 | RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API)
|
28 | 28 |
|
29 | 29 |
|
| 30 | +def get_targets(sdk_dir): |
| 31 | + if exists(join(sdk_dir, 'tools', 'bin', 'avdmanager')): |
| 32 | + avdmanager = sh.Command(join(sdk_dir, 'tools', 'bin', 'avdmanager')) |
| 33 | + targets = avdmanager('list', 'target').stdout.decode('utf-8').split('\n') |
| 34 | + elif exists(join(sdk_dir, 'tools', 'android')): |
| 35 | + android = sh.Command(join(sdk_dir, 'tools', 'android')) |
| 36 | + targets = android('list').stdout.decode('utf-8').split('\n') |
| 37 | + else: |
| 38 | + raise BuildInterruptingException( |
| 39 | + 'Could not find `android` or `sdkmanager` binaries in Android SDK', |
| 40 | + instructions='Make sure the path to the Android SDK is correct') |
| 41 | + return targets |
| 42 | + |
| 43 | + |
| 44 | +def get_available_apis(sdk_dir): |
| 45 | + targets = get_targets(sdk_dir) |
| 46 | + apis = [s for s in targets if re.match(r'^ *API level: ', s)] |
| 47 | + apis = [re.findall(r'[0-9]+', s) for s in apis] |
| 48 | + apis = [int(s[0]) for s in apis if s] |
| 49 | + return apis |
| 50 | + |
| 51 | + |
30 | 52 | class Context(object):
|
31 | 53 | '''A build context. If anything will be built, an instance this class
|
32 | 54 | will be instantiated and used to hold all the build state.'''
|
@@ -238,20 +260,7 @@ def prepare_build_environment(self,
|
238 | 260 | self.android_api = android_api
|
239 | 261 |
|
240 | 262 | check_target_api(android_api, self.archs[0].arch)
|
241 |
| - |
242 |
| - if exists(join(sdk_dir, 'tools', 'bin', 'avdmanager')): |
243 |
| - avdmanager = sh.Command(join(sdk_dir, 'tools', 'bin', 'avdmanager')) |
244 |
| - targets = avdmanager('list', 'target').stdout.decode('utf-8').split('\n') |
245 |
| - elif exists(join(sdk_dir, 'tools', 'android')): |
246 |
| - android = sh.Command(join(sdk_dir, 'tools', 'android')) |
247 |
| - targets = android('list').stdout.decode('utf-8').split('\n') |
248 |
| - else: |
249 |
| - raise BuildInterruptingException( |
250 |
| - 'Could not find `android` or `sdkmanager` binaries in Android SDK', |
251 |
| - instructions='Make sure the path to the Android SDK is correct') |
252 |
| - apis = [s for s in targets if re.match(r'^ *API level: ', s)] |
253 |
| - apis = [re.findall(r'[0-9]+', s) for s in apis] |
254 |
| - apis = [int(s[0]) for s in apis if s] |
| 263 | + apis = get_available_apis(self.sdk_dir) |
255 | 264 | info('Available Android APIs are ({})'.format(
|
256 | 265 | ', '.join(map(str, apis))))
|
257 | 266 | if android_api in apis:
|
|
0 commit comments