Skip to content

Commit 0167c2f

Browse files
committed
Added build-tools version check for ant/gradle selection
1 parent e44c871 commit 0167c2f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pythonforandroid/toolchain.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def check_python_dependencies():
7878
import imp
7979
from appdirs import user_data_dir
8080
import logging
81+
from distutils.version import LooseVersion
8182

8283
from pythonforandroid.recipe import (Recipe, PythonRecipe, CythonRecipe,
8384
CompiledComponentsPythonRecipe,
@@ -768,12 +769,24 @@ def apk(self, args):
768769
build_type = ctx.java_build_tool
769770
if build_type == 'auto':
770771
info('Selecting java build tool:')
771-
if exists('gradlew'):
772+
773+
build_tools_versions = os.listdir(join(ctx.sdk_dir, 'build-tools'))
774+
build_tools_versions = sorted(build_tools_versions,
775+
key=LooseVersion)
776+
build_tools_version = build_tools_versions[-1]
777+
info(('Detected highest available build tools '
778+
'version to be {}').format(build_tools_version))
779+
780+
if build_tools_version >= '25.0' and exists('gradlew'):
772781
build_type = 'gradle'
773782
info(' Building with gradle, as gradle executable is present')
774783
else:
775784
build_type = 'ant'
776-
info(' Building with ant, as no gradle executable detected')
785+
if build_tools_version < '25.0':
786+
info((' Building with ant, as the highest '
787+
'build-tools-version is only {}').format(build_tools_version))
788+
else:
789+
info(' Building with ant, as no gradle executable detected')
777790

778791
if build_type == 'gradle':
779792
# gradle-based build

0 commit comments

Comments
 (0)