Checks that build dependencies exist and sets internal variables for the Android SDK etc. ..warning:: This *must* be called before trying any build stuff
(self,
user_sdk_dir,
user_ndk_dir,
user_android_api,
user_ndk_api)
| 224 | self._ndk_dir = value |
| 225 | |
| 226 | def prepare_build_environment(self, |
| 227 | user_sdk_dir, |
| 228 | user_ndk_dir, |
| 229 | user_android_api, |
| 230 | user_ndk_api): |
| 231 | '''Checks that build dependencies exist and sets internal variables |
| 232 | for the Android SDK etc. |
| 233 | |
| 234 | ..warning:: This *must* be called before trying any build stuff |
| 235 | |
| 236 | ''' |
| 237 | |
| 238 | self.ensure_dirs() |
| 239 | |
| 240 | if self._build_env_prepared: |
| 241 | return |
| 242 | |
| 243 | # Work out where the Android SDK is |
| 244 | sdk_dir = None |
| 245 | if user_sdk_dir: |
| 246 | sdk_dir = user_sdk_dir |
| 247 | # This is the old P4A-specific var |
| 248 | if sdk_dir is None: |
| 249 | sdk_dir = environ.get('ANDROIDSDK', None) |
| 250 | # This seems used more conventionally |
| 251 | if sdk_dir is None: |
| 252 | sdk_dir = environ.get('ANDROID_HOME', None) |
| 253 | # Checks in the buildozer SDK dir, useful for debug tests of p4a |
| 254 | if sdk_dir is None: |
| 255 | possible_dirs = glob.glob(expanduser(join( |
| 256 | '~', '.buildozer', 'android', 'platform', 'android-sdk-*'))) |
| 257 | possible_dirs = [d for d in possible_dirs if not |
| 258 | d.endswith(('.bz2', '.gz'))] |
| 259 | if possible_dirs: |
| 260 | info('Found possible SDK dirs in buildozer dir: {}'.format( |
| 261 | ', '.join(d.split(os.sep)[-1] for d in possible_dirs))) |
| 262 | info('Will attempt to use SDK at {}'.format(possible_dirs[0])) |
| 263 | warning('This SDK lookup is intended for debug only, if you ' |
| 264 | 'use python-for-android much you should probably ' |
| 265 | 'maintain your own SDK download.') |
| 266 | sdk_dir = possible_dirs[0] |
| 267 | if sdk_dir is None: |
| 268 | raise BuildInterruptingException('Android SDK dir was not specified, exiting.') |
| 269 | self.sdk_dir = realpath(sdk_dir) |
| 270 | |
| 271 | # Check what Android API we're using |
| 272 | android_api = None |
| 273 | if user_android_api: |
| 274 | android_api = user_android_api |
| 275 | info('Getting Android API version from user argument: {}'.format(android_api)) |
| 276 | elif 'ANDROIDAPI' in environ: |
| 277 | android_api = environ['ANDROIDAPI'] |
| 278 | info('Found Android API target in $ANDROIDAPI: {}'.format(android_api)) |
| 279 | else: |
| 280 | info('Android API target was not set manually, using ' |
| 281 | 'the default of {}'.format(RECOMMENDED_TARGET_API)) |
| 282 | android_api = RECOMMENDED_TARGET_API |
| 283 | android_api = int(android_api) |