Disable Google Services Gradle plugin for specific flavour
Asked Answered
S

2

19

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?

Splatter answered 24/1, 2018 at 8:55 Comment(0)
S
24

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
    }
}
Sabadell answered 15/3, 2018 at 16:32 Comment(0)
S
0

In a more modern setup, you can also set the strategy when its missing.

productFlavors {
    create("dev") {
        dimension = "version"
        applicationIdSuffix = ".dev"
        googleServices.missingGoogleServicesStrategy = GoogleServicesPlugin.MissingGoogleServicesStrategy.WARN
    }
 }
Saleable answered 26/7, 2024 at 13:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.