Skip to content

Commit

Permalink
Add support for additional Gradle plugins
Browse files Browse the repository at this point in the history
Some Google Android features such as Firebase Crashlytics are enabled
with Gradle plugins. Add support for specifying additional plugins in
`build.gradle`.
  • Loading branch information
dbnicholson committed Oct 21, 2022
1 parent b89734a commit 8a506ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/source/buildoptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ options (this list may not be exhaustive):
- ``--enable-google-services``: Enable the Google Services Gradle plugin.
This option requires a ``google-services.json`` file in root of the
project directory.
- ``--add-gradle-plugins``: Add a plugin for gradle. The format of the option
is ``<plugin-id>:<classpath>``. The option can be specified multiple times.


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


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


Requirements blacklist (APK size optimization)
Expand Down
14 changes: 14 additions & 0 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,13 @@ def make_package(args):
if args.enable_google_services:
shutil.copy(args.google_services_json, 'src/google-services.json')

# Convert the gradle_plugins args to a list of dicts with id and
# classpath keys.
gradle_plugins = [
dict(zip(('id', 'classpath'), spec.split(':', maxsplit=1)))
for spec in args.gradle_plugins
]

# gradle build templates
render(
'build.tmpl.gradle',
Expand All @@ -562,6 +569,7 @@ def make_package(args):
build_tools_version=build_tools_version,
debug_build="debug" in args.build_mode,
is_library=(get_bootstrap_name() == 'service_library'),
gradle_plugins=gradle_plugins,
)

# gradle properties
Expand Down Expand Up @@ -764,6 +772,12 @@ def parse_args_and_make_package(args=None):
default=[],
action='append',
help='Ddd a repository for gradle')
ap.add_argument('--add-gradle-plugin', dest='gradle_plugins',
default=[],
action='append',
help=('Add a plugin for gradle. The format of the option '
'is <plugin-id>:<classpath>. The option can be '
'specified multiple times.'))
ap.add_argument('--add-packaging-option', dest='packaging_options',
default=[],
action='append',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ buildscript {
{% if args.enable_google_services %}
classpath 'com.google.gms:google-services:4.3.14'
{% endif %}
{% for plugin in gradle_plugins %}
classpath '{{ plugin.classpath }}'
{% endfor %}
}
}

Expand All @@ -33,6 +36,9 @@ apply plugin: 'com.android.application'
{% if args.enable_google_services %}
apply plugin: 'com.google.gms.google-services'
{% endif %}
{% for plugin in gradle_plugins %}
apply plugin: '{{ plugin.id }}'
{% endfor %}

android {
compileSdkVersion {{ android_api }}
Expand Down

0 comments on commit 8a506ef

Please sign in to comment.