@@ -79,6 +79,7 @@ def check_python_dependencies():
7979import imp
8080from appdirs import user_data_dir
8181import logging
82+ from distutils .version import LooseVersion
8283
8384from pythonforandroid .recipe import (Recipe , PythonRecipe , CythonRecipe ,
8485 CompiledComponentsPythonRecipe ,
@@ -771,12 +772,24 @@ def apk(self, args):
771772 build_type = ctx .java_build_tool
772773 if build_type == 'auto' :
773774 info ('Selecting java build tool:' )
774- if exists ('gradlew' ):
775+
776+ build_tools_versions = os .listdir (join (ctx .sdk_dir , 'build-tools' ))
777+ build_tools_versions = sorted (build_tools_versions ,
778+ key = LooseVersion )
779+ build_tools_version = build_tools_versions [- 1 ]
780+ info (('Detected highest available build tools '
781+ 'version to be {}' ).format (build_tools_version ))
782+
783+ if build_tools_version >= '25.0' and exists ('gradlew' ):
775784 build_type = 'gradle'
776785 info (' Building with gradle, as gradle executable is present' )
777786 else :
778787 build_type = 'ant'
779- info (' Building with ant, as no gradle executable detected' )
788+ if build_tools_version < '25.0' :
789+ info ((' Building with ant, as the highest '
790+ 'build-tools-version is only {}' ).format (build_tools_version ))
791+ else :
792+ info (' Building with ant, as no gradle executable detected' )
780793
781794 if build_type == 'gradle' :
782795 # gradle-based build
0 commit comments