Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Google Services Gradle plugin for specific flavour

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?

like image 498
southrop Avatar asked Jan 24 '18 08:01

southrop


People also ask

How do I use a different Google-services JSON file with multiple product flavors Android?

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.

Where is google-services JSON file?

The google-services. json file is generally placed in the app/ directory (at the root of the Android Studio app module).

What is the use of Google-services json?

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.


1 Answers

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
    }
}
like image 191
Jack Feng Avatar answered Sep 22 '22 09:09

Jack Feng