【问题标题】:Conditionally apply GMS google-services plugin有条件地应用 GMS google-services 插件
【发布时间】:2017-07-30 10:49:25
【问题描述】:

多年来,我一直非常小心地不将 Google-Android 依赖项引入我的 Android 应用程序,并且有两种风格保持这种隔离,withAmazonwithGoogle

app
 |_ main
 |_ test
 |_ withAmazon
 |_ withGoogle

最近,我一直在试验 Firebase Analytics,这是一个非常类似于 Google OHA only 的产品,我不认为它可以在 Google 生态系统之外工作(尽管有 @987654322 @确实如此)。 firebase 的部分设置是应用 google-services 插件。

 apply plugin: 'com.google.gms.google-services'

但是,withAmazon 风格不包括 google-service.json ...因为...嗯,它不适合 Google。

app
 |_ main
 |_ test
 |_ withAmazon
    |- java
    |- AndroidManifest.xml
 |_ withGoogle
    |- java
    |- AndroidManifest.xml
    |- google-services.json

...但是由于Gradle plugins appear to need to have to be applied project wide 是否可以仅将 gms 插件应用于其中一种风味?在编译 Amazon 风格时,在上述场景中构建失败,因为它抱怨 google-services.json 不存在......这是正确的。

目前,我的解决方法是将google-services.json 移动到app/ 目录下。问题解决了。但是,我感觉 Google 和“纯”Android 操作系统之间的明确界限正在被侵犯。

任何慷慨的帮助。

【问题讨论】:

  • 然后将 firebase 设为 withGoogle 风味的一部分,或者将 google-services.json 移至主要风味。

标签: android kindle-fire google-play-services


【解决方案1】:

我通过像这样修改我的父 build.gradle 文件解决了这个问题;

if (getGradle().getStartParameter().getTaskRequests().toString().contains(withGoogleFlavor)){
    apply plugin: 'com.google.gms.google-services'
}

现在插件(和相关的 Google Play 服务依赖项)没有添加到我的应用程序的亚马逊风格中。此外,google-services.json 现在又回到了“withGoogle”的风格。

注意:withGoogle 是在别处定义的定义,其值为“withGoogle”。 鸣谢:https://stackoverflow.com/a/43336869/1348379

【讨论】:

    猜你喜欢
    • 2016-11-21
    • 1970-01-01
    • 2019-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多