@@ -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