Skip to content

Commit 2882c21

Browse files
committed
Add support for Google Services gradle plugin
The Google Services gradle plugin[1] helps enable use of Google services in Android apps. Since this requires a `google-services.json` file to be copied into the build directory, it needs to be a separate option in addition to enabling the plugin in the `build.gradle` file. 1. https://developers.google.com/android/guides/google-services-plugin
1 parent 6cd170a commit 2882c21

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

doc/source/buildoptions.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ options (this list may not be exhaustive):
9191
- ``--add-source``: Add a source directory to the app's Java code.
9292
- ``--no-compile-pyo``: Do not optimise .py files to .pyo.
9393
- ``--enable-androidx``: Enable AndroidX support library.
94+
- ``--enable-google-services``: Enable the Google Services Gradle plugin.
95+
This option requires a ``google-services.json`` file in root of the
96+
project directory.
9497

9598

9699
webview
@@ -152,6 +155,9 @@ ready.
152155
- ``add-source``: Add a source directory to the app's Java code.
153156
- ``--port``: The port on localhost that the WebView will
154157
access. Defaults to 5000.
158+
- ``--enable-google-services``: Enable the Google Services Gradle plugin.
159+
This option requires a ``google-services.json`` file in root of the
160+
project directory.
155161

156162

157163
service_library
@@ -177,6 +183,9 @@ systems and frameworks.
177183
- ``--add-jar``: The path to a .jar file to include in the APK. To
178184
include multiple jar files, pass this argument multiple times.
179185
- ``add-source``: Add a source directory to the app's Java code.
186+
- ``--enable-google-services``: Enable the Google Services Gradle plugin.
187+
This option requires a ``google-services.json`` file in root of the
188+
project directory.
180189

181190

182191
Requirements blacklist (APK size optimization)

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ def make_package(args):
548548
if args.fileprovider_paths:
549549
shutil.copy(args.fileprovider_paths, join(res_dir, "xml/file_paths.xml"))
550550

551+
if args.enable_google_services:
552+
shutil.copy('google-services.json', 'src/main/google-services.json')
553+
551554
# gradle build templates
552555
render(
553556
'build.tmpl.gradle',
@@ -864,6 +867,12 @@ def parse_args_and_make_package(args=None):
864867
ap.add_argument('--activity-class-name', dest='activity_class_name', default=DEFAULT_PYTHON_ACTIVITY_JAVA_CLASS,
865868
help='The full java class name of the main activity')
866869

870+
ap.add_argument('--enable-google-services', dest='enable_google_services',
871+
action='store_true',
872+
help=('Enable the Google Services Gradle plugin. '
873+
'This requires a google-services.json in the root '
874+
'of the project.'))
875+
867876
# Put together arguments, and add those from .p4a config file:
868877
if args is None:
869878
args = sys.argv[1:]
@@ -949,6 +958,12 @@ def _read_configuration():
949958
'--launcher (SDL2 bootstrap only)' +
950959
'to have something to launch inside the .apk!')
951960
sys.exit(1)
961+
962+
if args.enable_google_services and not exists('google-services.json'):
963+
print('You must provide a google-services.json file for '
964+
'--enable-google-services')
965+
sys.exit(1)
966+
952967
make_package(args)
953968

954969
return args

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ buildscript {
66
}
77
dependencies {
88
classpath 'com.android.tools.build:gradle:7.1.2'
9+
{% if args.enable_google_services %}
10+
classpath 'com.google.gms:google-services:4.3.14'
11+
{% endif %}
912
}
1013
}
1114

@@ -27,6 +30,9 @@ apply plugin: 'com.android.library'
2730
{% else %}
2831
apply plugin: 'com.android.application'
2932
{% endif %}
33+
{% if args.enable_google_services %}
34+
apply plugin: 'com.google.gms.google-services'
35+
{% endif %}
3036

3137
android {
3238
compileSdkVersion {{ android_api }}

0 commit comments

Comments
 (0)