1515from pythonforandroid .logger import (info , warning , info_notify , info_main , shprint )
1616from pythonforandroid .archs import ArchARM , ArchARMv7_a , ArchAarch_64 , Archx86 , Archx86_64
1717from pythonforandroid .recipe import CythonRecipe , Recipe
18-
19- DEFAULT_ANDROID_API = 15
20-
21- DEFAULT_NDK_API = 21
22-
18+ from pythonforandroid .recommendations import (
19+ check_ndk_version , check_target_api , check_ndk_api ,
20+ RECOMMENDED_NDK_API , RECOMMENDED_TARGET_API )
2321
2422class Context (object ):
2523 '''A build context. If anything will be built, an instance this class
@@ -140,19 +138,6 @@ def ndk_api(self):
140138 def ndk_api (self , value ):
141139 self ._ndk_api = value
142140
143- @property
144- def ndk_ver (self ):
145- '''The version of the NDK being used for compilation.'''
146- if self ._ndk_ver is None :
147- raise ValueError ('Tried to access ndk_ver but it has not '
148- 'been set - this should not happen, something '
149- 'went wrong!' )
150- return self ._ndk_ver
151-
152- @ndk_ver .setter
153- def ndk_ver (self , value ):
154- self ._ndk_ver = value
155-
156141 @property
157142 def sdk_dir (self ):
158143 '''The path to the Android SDK.'''
@@ -183,7 +168,6 @@ def prepare_build_environment(self,
183168 user_sdk_dir ,
184169 user_ndk_dir ,
185170 user_android_api ,
186- user_ndk_ver ,
187171 user_ndk_api ):
188172 '''Checks that build dependencies exist and sets internal variables
189173 for the Android SDK etc.
@@ -237,17 +221,12 @@ def prepare_build_environment(self,
237221 info ('Found Android API target in $ANDROIDAPI: {}' .format (android_api ))
238222 else :
239223 info ('Android API target was not set manually, using '
240- 'the default of {}' .format (DEFAULT_ANDROID_API ))
241- android_api = DEFAULT_ANDROID_API
224+ 'the default of {}' .format (RECOMMENDED_TARGET_API ))
225+ android_api = RECOMMENDED_TARGET_API
242226 android_api = int (android_api )
243227 self .android_api = android_api
244228
245- if self .android_api >= 21 and self .archs [0 ].arch == 'armeabi' :
246- raise BuildInterruptingException (
247- 'Asked to build for armeabi architecture with API '
248- '{}, but API 21 or greater does not support armeabi' .format (
249- self .android_api ),
250- instructions = 'You probably want to build with --arch=armeabi-v7a instead' )
229+ check_target_api (android_api , self .archs [0 ].arch )
251230
252231 if exists (join (sdk_dir , 'tools' , 'bin' , 'avdmanager' )):
253232 avdmanager = sh .Command (join (sdk_dir , 'tools' , 'bin' , 'avdmanager' ))
@@ -306,47 +285,7 @@ def prepare_build_environment(self,
306285 raise BuildInterruptingException ('Android NDK dir was not specified' )
307286 self .ndk_dir = realpath (ndk_dir )
308287
309- # Find the NDK version, and check it against what the NDK dir
310- # seems to report
311- ndk_ver = None
312- if user_ndk_ver :
313- ndk_ver = user_ndk_ver
314- if ndk_dir is not None :
315- info ('Got NDK version from from user argument: {}' .format (ndk_ver ))
316- if ndk_ver is None :
317- ndk_ver = environ .get ('ANDROIDNDKVER' , None )
318- if ndk_ver is not None :
319- info ('Got NDK version from $ANDROIDNDKVER: {}' .format (ndk_ver ))
320-
321- self .ndk = 'google'
322-
323- try :
324- with open (join (ndk_dir , 'RELEASE.TXT' )) as fileh :
325- reported_ndk_ver = fileh .read ().split (' ' )[0 ].strip ()
326- except IOError :
327- pass
328- else :
329- if reported_ndk_ver .startswith ('crystax-ndk-' ):
330- reported_ndk_ver = reported_ndk_ver [12 :]
331- self .ndk = 'crystax'
332- if ndk_ver is None :
333- ndk_ver = reported_ndk_ver
334- info (('Got Android NDK version from the NDK dir: {}' ).format (ndk_ver ))
335- else :
336- if ndk_ver != reported_ndk_ver :
337- warning ('NDK version was set as {}, but checking '
338- 'the NDK dir claims it is {}.' .format (
339- ndk_ver , reported_ndk_ver ))
340- warning ('The build will try to continue, but it may '
341- 'fail and you should check '
342- 'that your setting is correct.' )
343- warning ('If the NDK dir result is correct, you don\' t '
344- 'need to manually set the NDK ver.' )
345- if ndk_ver is None :
346- warning ('Android NDK version could not be found. This probably'
347- 'won\' t cause any problems, but if necessary you can'
348- 'set it with `--ndk-version=...`.' )
349- self .ndk_ver = ndk_ver
288+ check_ndk_version (ndk_dir )
350289
351290 ndk_api = None
352291 if user_ndk_api :
@@ -356,21 +295,14 @@ def prepare_build_environment(self,
356295 ndk_api = environ .get ('NDKAPI' , None )
357296 info ('Found Android API target in $NDKAPI' )
358297 else :
359- ndk_api = min (self .android_api , DEFAULT_NDK_API )
298+ ndk_api = min (self .android_api , RECOMMENDED_NDK_API )
360299 warning ('NDK API target was not set manually, using '
361300 'the default of {} = min(android-api={}, default ndk-api={})' .format (
362- ndk_api , self .android_api , DEFAULT_NDK_API ))
301+ ndk_api , self .android_api , RECOMMENDED_NDK_API ))
363302 ndk_api = int (ndk_api )
364303 self .ndk_api = ndk_api
365304
366- if self .ndk_api > self .android_api :
367- raise BuildInterruptingException (
368- 'Target NDK API is {}, higher than the target Android API {}.' .format (
369- self .ndk_api , self .android_api ),
370- instructions = ('The NDK API is a minimum supported API number and must be lower '
371- 'than the target Android API' ))
372-
373- info ('Using {} NDK {}' .format (self .ndk .capitalize (), self .ndk_ver ))
305+ check_ndk_api (ndk_api , self .android_api )
374306
375307 virtualenv = None
376308 if virtualenv is None :
@@ -483,7 +415,6 @@ def __init__(self):
483415 self ._ndk_dir = None
484416 self ._android_api = None
485417 self ._ndk_api = None
486- self ._ndk_ver = None
487418 self .ndk = None
488419
489420 self .toolchain_prefix = None
0 commit comments