Android 有条件地应用GMS谷歌服务插件
多年来,我一直非常小心地避免在我的Android应用程序中引入Google Android依赖项,并且有两种风格保持这种分离,Android 有条件地应用GMS谷歌服务插件,android,kindle-fire,google-play-services,Android,Kindle Fire,Google Play Services,多年来,我一直非常小心地避免在我的Android应用程序中引入Google Android依赖项,并且有两种风格保持这种分离,与Amazon和与Google app |_ main |_ test |_ withAmazon |_ withGoogle 最近,我一直在尝试Firebase Analytics,这在很大程度上是一个产品,我不相信它是为了在谷歌生态系统之外工作(尽管有它)。firebase的部分设置是应用谷歌服务插件 apply plugin: 'com.google.g
与Amazon
和与Google
app
|_ main
|_ test
|_ withAmazon
|_ withGoogle
最近,我一直在尝试Firebase Analytics,这在很大程度上是一个产品,我不相信它是为了在谷歌生态系统之外工作(尽管有它)。firebase的部分设置是应用谷歌服务
插件
apply plugin: 'com.google.gms.google-services'
然而,亚马逊的风格不包括google服务.json
…因为……好吧,这不是谷歌的风格
app
|_ main
|_ test
|_ withAmazon
|- java
|- AndroidManifest.xml
|_ withGoogle
|- java
|- AndroidManifest.xml
|- google-services.json
…但既然gms插件只能应用于其中一种口味,那又有可能吗?编译Amazon flavor时,构建在上述场景中失败,因为它抱怨google services.json
不存在……这是正确的
现在,我的解决办法是将googleservices.json
移动到app/
目录下。问题解决了。然而,我认为谷歌和“纯”安卓操作系统之间的界限被侵犯是不对的
我通过修改我的父build.gradle文件解决了这个问题
if (getGradle().getStartParameter().getTaskRequests().toString().contains(withGoogleFlavor)){
apply plugin: 'com.google.gms.google-services'
}
现在,插件(以及相关的Google Play服务依赖项)并没有添加到我的应用程序的Amazon风格中。此外,googleservices.json
现在又回到了“withGoogle”风格
注意:withGoogle
是在别处定义的def,其值为“withGoogle”。
确认:然后使用google
flavor将firebase仅作为的一部分,或者将google services.json
移动到主flavor。