The usage of Google Services requires the use of this Gradle plugin:
apply plugin: 'com.google.gms.google-services'
This thread on the Gradle forum has lead me to conclude that you can't selectively enable or disable a plugin, meaning that is not an option. I've tried a number of solutions offered by older threads involving conditionals surrounding the apply plugin
statement and none of them work now.
The plugin itself is configured by a google-services.json
that Google generates and is placed into the project directory. I'm aware that you can have different configurations for each flavour by having multiple google-services.json
files, but what are we meant to do for build flavours that we explicitly want to not use Google Services (e.g. for targeting devices that do not have Play Services installed)? Blank files or dummy JSON files don't work as the plugin will refuse to accept it.
So the only solution that I can think of would be to manually disable the plugin (comment out that line) each time I want to test/build my flavour. Surely there has to be a better way to control how the plugin works?
How to use this file for different product flavors. There are only 3 steps first step is so simple just remove the google-service. json file from the root of the app/ module and save it your local system directory for the save side, & then make your product flavors like Production & Staging environment.
The google-services. json file is generally placed in the app/ directory (at the root of the Android Studio app module).
The google-services. json file created in this doc is used within your app to connect to firebase and facilitate Android Push Notifications and is normally labelled google-services. json.
I finally got a version to work. Tested with gradle 4.6, build tools 3.0.1, google-services plugin 3.1.1
apply plugin: 'com.google.gms.google-services' android.applicationVariants.all { variant -> if (variant.name == 'someVariantNameYouDontwantFirebase') { project.tasks.getByName('process' + variant.name.capitalize() + 'GoogleServices').enabled = false } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With