Skip to content

Commit fbfc134

Browse files
committed
Added --java-build-tool option for ant vs gradle
1 parent c1db1a6 commit fbfc134

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pythonforandroid/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Context(object):
4747

4848
symlink_java_src = False # If True, will symlink instead of copying during build
4949

50+
java_build_tool = 'auto'
51+
5052
@property
5153
def packages_path(self):
5254
'''Where packages are downloaded before being unpacked'''

pythonforandroid/toolchain.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ def __init__(self):
328328
dest='local_recipes', default='./p4a-recipes',
329329
help='Directory to look for local recipes')
330330

331+
generic_parser.add_argument(
332+
'--java-build-tool',
333+
dest='java_build_tool', default='auto',
334+
choices=['auto', 'ant', 'gradle'],
335+
help=('The java build tool to use when packaging the APK, defaults '
336+
'to automatically selecting an appropriate tool.'))
337+
331338
add_boolean_option(
332339
generic_parser, ['copy-libs'],
333340
default=False,
@@ -501,6 +508,7 @@ def add_parser(subparsers, *args, **kwargs):
501508
self.android_api = args.android_api
502509
self.ndk_version = args.ndk_version
503510
self.ctx.symlink_java_src = args.symlink_java_src
511+
self.ctx.java_build_tool = args.java_build_tool
504512

505513
self._archs = split_argument_list(args.arch)
506514

@@ -760,7 +768,17 @@ def apk(self, args):
760768
self.hook("after_apk_build")
761769
self.hook("before_apk_assemble")
762770

763-
if exists(join(dist.dist_dir, "templates", "build.tmpl.gradle")):
771+
build_type = ctx.java_build_tool
772+
if build_type == 'auto':
773+
info('Selecting java build tool:')
774+
if exists('gradlew'):
775+
build_type == 'gradle'
776+
info(' Building with gradle, as gradle executable is present')
777+
else:
778+
build_type == 'ant'
779+
info(' Building with ant, as no gradle executable detected')
780+
781+
if build_type == 'gradle':
764782
# gradle-based build
765783
env["ANDROID_NDK_HOME"] = self.ctx.ndk_dir
766784
env["ANDROID_HOME"] = self.ctx.sdk_dir

0 commit comments

Comments
 (0)