针对特定风格

时间:2018-01-24 08:55:39

标签: android gradle-plugin google-play-services

Google服务的使用需要使用此Gradle插件:

apply plugin: 'com.google.gms.google-services'
Gradle论坛上的

This thread让我得出结论,你不能有选择地启用或禁用插件,这意味着这不是一个选项。我已经尝试了一些旧线程提供的解决方案,这些解决方案涉及apply plugin语句周围的条件,现在都没有。

插件本身由Google生成的google-services.json配置,并放置在项目目录中。我知道您可以通过multiple google-services.json files为每种风格配置不同的配置,但我们打算为构建风格做什么,我们明确希望使用Google服务(例如,定位未安装Play服务的设备?空白文件或虚拟JSON文件不起作用,因为插件将拒绝接受它。

因此,我能想到的唯一解决方案是每次我想测试/构建我的味道时手动禁用插件(注释掉该行)。当然必须有更好的方法来控制插件的工作方式吗?

1 个答案:

答案 0 :(得分:6)

我终于得到了一个版本。使用gradle 4.6,构建工具3.0.1,google-services插件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
    }
}