add support for gradle dependencies and aar

This commit is contained in:
Mathieu Virbel 2017-05-07 00:06:22 +02:00
parent bb643ce15b
commit a9de15a905
3 changed files with 27 additions and 5 deletions

View file

@ -144,6 +144,14 @@ fullscreen = 0
# directory containing the files) # directory containing the files)
#android.add_src = #android.add_src =
# (list) Android AAR archives to add (currently works only with sdl2_gradle
# bootstrap)
#android.add_aars =
# (list) Gradle dependencies to add (currently works only with sdl2_gradle
# bootstrap)
#android.gradle_dependencies =
# (str) python-for-android branch to use, if not master, useful to try # (str) python-for-android branch to use, if not master, useful to try
# not yet merged features. # not yet merged features.
#android.branch = master #android.branch = master

View file

@ -845,6 +845,9 @@ class TargetAndroid(Target):
def _add_java_src(self, dist_dir): def _add_java_src(self, dist_dir):
java_src = self.buildozer.config.getlist('app', 'android.add_src', []) java_src = self.buildozer.config.getlist('app', 'android.add_src', [])
if exists(join(dist_dir, "build.gradle")):
src_dir = join(dist_dir, "src", "main", "java")
else:
src_dir = join(dist_dir, 'src') src_dir = join(dist_dir, 'src')
for pattern in java_src: for pattern in java_src:
for fn in glob(expanduser(pattern.strip())): for fn in glob(expanduser(pattern.strip())):

View file

@ -4,9 +4,8 @@ Android target, based on python-for-android project (new toolchain)
''' '''
import sys import sys
import buildozer
from buildozer.targets.android import TargetAndroid
from buildozer import USE_COLOR from buildozer import USE_COLOR
from buildozer.targets.android import TargetAndroid
from os.path import join, expanduser, realpath from os.path import join, expanduser, realpath
@ -17,8 +16,8 @@ class TargetAndroidNew(TargetAndroid):
p4a_apk_cmd = "apk --debug --bootstrap=" p4a_apk_cmd = "apk --debug --bootstrap="
extra_p4a_args = '' extra_p4a_args = ''
def __init__(self, buildozer): def __init__(self, *args, **kwargs):
super(TargetAndroidNew, self).__init__(buildozer) super(TargetAndroidNew, self).__init__(*args, **kwargs)
self._build_dir = join(self.buildozer.platform_dir, 'build') self._build_dir = join(self.buildozer.platform_dir, 'build')
executable = sys.executable or 'python' executable = sys.executable or 'python'
self._p4a_cmd = '{} -m pythonforandroid.toolchain '.format(executable) self._p4a_cmd = '{} -m pythonforandroid.toolchain '.format(executable)
@ -134,6 +133,18 @@ class TargetAndroidNew(TargetAndroid):
cmd.append('--blacklist') cmd.append('--blacklist')
cmd.append(realpath(blacklist_src)) cmd.append(realpath(blacklist_src))
# support for aars
aars = self.buildozer.config.getlist('app', 'android.add_aars', [])
for aar in aars:
cmd.append('--add-aar')
cmd.append(realpath(aar))
# support for gradle dependencies
gradle_dependencies = self.buildozer.config.getlist('app', 'android.gradle_dependencies', [])
for gradle_dependency in gradle_dependencies:
cmd.append('--depend')
cmd.append(gradle_dependency)
cmd.append('--arch') cmd.append('--arch')
cmd.append(self.buildozer.config.getdefault('app', 'android.arch', "armeabi-v7a")) cmd.append(self.buildozer.config.getdefault('app', 'android.arch', "armeabi-v7a"))