Skip to content

Commit 8a506ef

Browse files
committed
Add support for additional Gradle plugins
Some Google Android features such as Firebase Crashlytics are enabled with Gradle plugins. Add support for specifying additional plugins in `build.gradle`.
1 parent b89734a commit 8a506ef

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

doc/source/buildoptions.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ options (this list may not be exhaustive):
9494
- ``--enable-google-services``: Enable the Google Services Gradle plugin.
9595
This option requires a ``google-services.json`` file in root of the
9696
project directory.
97+
- ``--add-gradle-plugins``: Add a plugin for gradle. The format of the option
98+
is ``<plugin-id>:<classpath>``. The option can be specified multiple times.
9799

98100

99101
webview
@@ -158,6 +160,8 @@ ready.
158160
- ``--enable-google-services``: Enable the Google Services Gradle plugin.
159161
This option requires a ``google-services.json`` file in root of the
160162
project directory.
163+
- ``--add-gradle-plugins``: Add a plugin for gradle. The format of the option
164+
is ``<plugin-id>:<classpath>``. The option can be specified multiple times.
161165

162166

163167
service_library
@@ -186,6 +190,8 @@ systems and frameworks.
186190
- ``--enable-google-services``: Enable the Google Services Gradle plugin.
187191
This option requires a ``google-services.json`` file in root of the
188192
project directory.
193+
- ``--add-gradle-plugin``: Add a plugin for gradle. The format of the option
194+
is ``<plugin-id>:<classpath>``. The option can be specified multiple times.
189195

190196

191197
Requirements blacklist (APK size optimization)

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,13 @@ def make_package(args):
551551
if args.enable_google_services:
552552
shutil.copy(args.google_services_json, 'src/google-services.json')
553553

554+
# Convert the gradle_plugins args to a list of dicts with id and
555+
# classpath keys.
556+
gradle_plugins = [
557+
dict(zip(('id', 'classpath'), spec.split(':', maxsplit=1)))
558+
for spec in args.gradle_plugins
559+
]
560+
554561
# gradle build templates
555562
render(
556563
'build.tmpl.gradle',
@@ -562,6 +569,7 @@ def make_package(args):
562569
build_tools_version=build_tools_version,
563570
debug_build="debug" in args.build_mode,
564571
is_library=(get_bootstrap_name() == 'service_library'),
572+
gradle_plugins=gradle_plugins,
565573
)
566574

567575
# gradle properties
@@ -764,6 +772,12 @@ def parse_args_and_make_package(args=None):
764772
default=[],
765773
action='append',
766774
help='Ddd a repository for gradle')
775+
ap.add_argument('--add-gradle-plugin', dest='gradle_plugins',
776+
default=[],
777+
action='append',
778+
help=('Add a plugin for gradle. The format of the option '
779+
'is <plugin-id>:<classpath>. The option can be '
780+
'specified multiple times.'))
767781
ap.add_argument('--add-packaging-option', dest='packaging_options',
768782
default=[],
769783
action='append',

pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ buildscript {
99
{% if args.enable_google_services %}
1010
classpath 'com.google.gms:google-services:4.3.14'
1111
{% endif %}
12+
{% for plugin in gradle_plugins %}
13+
classpath '{{ plugin.classpath }}'
14+
{% endfor %}
1215
}
1316
}
1417

@@ -33,6 +36,9 @@ apply plugin: 'com.android.application'
3336
{% if args.enable_google_services %}
3437
apply plugin: 'com.google.gms.google-services'
3538
{% endif %}
39+
{% for plugin in gradle_plugins %}
40+
apply plugin: '{{ plugin.id }}'
41+
{% endfor %}
3642

3743
android {
3844
compileSdkVersion {{ android_api }}

0 commit comments

Comments
 (0)