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
18+ from pythonforandroid .recommendations import (
19+ check_ndk_version , check_target_api , check_ndk_api ,
20+ RECOMMENDED_NDK_API , RECOMMENDED_TARGET_API )
2221
2322
2423class Context (object ):
@@ -140,19 +139,6 @@ def ndk_api(self):
140139 def ndk_api (self , value ):
141140 self ._ndk_api = value
142141
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-
156142 @property
157143 def sdk_dir (self ):
158144 '''The path to the Android SDK.'''
@@ -183,7 +169,6 @@ def prepare_build_environment(self,
183169 user_sdk_dir ,
184170 user_ndk_dir ,
185171 user_android_api ,
186- user_ndk_ver ,
187172 user_ndk_api ):
188173 '''Checks that build dependencies exist and sets internal variables
189174 for the Android SDK etc.
@@ -237,17 +222,12 @@ def prepare_build_environment(self,
237222 info ('Found Android API target in $ANDROIDAPI: {}' .format (android_api ))
238223 else :
239224 info ('Android API target was not set manually, using '
240- 'the default of {}' .format (DEFAULT_ANDROID_API ))
241- android_api = DEFAULT_ANDROID_API
225+ 'the default of {}' .format (RECOMMENDED_TARGET_API ))
226+ android_api = RECOMMENDED_TARGET_API
242227 android_api = int (android_api )
243228 self .android_api = android_api
244229
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' )
230+ check_target_api (android_api , self .archs [0 ].arch )
251231
252232 if exists (join (sdk_dir , 'tools' , 'bin' , 'avdmanager' )):
253233 avdmanager = sh .Command (join (sdk_dir , 'tools' , 'bin' , 'avdmanager' ))
@@ -306,47 +286,7 @@ def prepare_build_environment(self,
306286 raise BuildInterruptingException ('Android NDK dir was not specified' )
307287 self .ndk_dir = realpath (ndk_dir )
308288
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
289+ check_ndk_version (ndk_dir )
350290
351291 ndk_api = None
352292 if user_ndk_api :
@@ -356,21 +296,14 @@ def prepare_build_environment(self,
356296 ndk_api = environ .get ('NDKAPI' , None )
357297 info ('Found Android API target in $NDKAPI' )
358298 else :
359- ndk_api = min (self .android_api , DEFAULT_NDK_API )
299+ ndk_api = min (self .android_api , RECOMMENDED_NDK_API )
360300 warning ('NDK API target was not set manually, using '
361301 'the default of {} = min(android-api={}, default ndk-api={})' .format (
362- ndk_api , self .android_api , DEFAULT_NDK_API ))
302+ ndk_api , self .android_api , RECOMMENDED_NDK_API ))
363303 ndk_api = int (ndk_api )
364304 self .ndk_api = ndk_api
365305
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 ))
306+ check_ndk_api (ndk_api , self .android_api )
374307
375308 virtualenv = None
376309 if virtualenv is None :
@@ -483,7 +416,6 @@ def __init__(self):
483416 self ._ndk_dir = None
484417 self ._android_api = None
485418 self ._ndk_api = None
486- self ._ndk_ver = None
487419 self .ndk = None
488420
489421 self .toolchain_prefix = None
0 commit comments