我可以针对特定口味禁用Firebase插件吗? [英] Can i disable Firebase plugin for specific flavor?

查看:71
本文介绍了我可以针对特定口味禁用Firebase插件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试Firebase分析套件,但是,我遇到了一个小问题,我的应用同时在Google Play和Amazon Store(不支持Google Play服务)中分发.我想删除对Firebase的依赖关系(我已经知道该怎么做),但是,我还需要删除Firebase插件,以便在构建时不会引发异常.

I'm currently trying out the Firebase analytics suit, but, i have faced one small issue, my app is distributed on both google play and amazon store (which doesn't support google play services), so for the amazon flavor i want to remove the dependency to Firebase (which i already know how to do), but, i also need to remove the Firebase plugin, so that it doesn't throw an exception while building.

这是我目前所拥有的:

productFlavors {
    google {
        applicationId 'google app id'
    }
    amazon {
        applicationId 'amazon app id'
    }
}

dependencies {
    googleCompile 'com.google.firebase:firebase-analytics:9.0.0'
    amazonCompile 'com.amazonaws:aws-android-sdk-mobileanalytics:2.2.12'
    amazonCompile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;
    }
}

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

但是,只有在亚马逊风格的情况下,我才需要删除插件.

But, i need to remove the plugin only if is the amazon flavor.

这甚至有可能吗?还是至少有我可以尝试的东西?

Is this even possible? Or at least is there something close that i can try ?

更新:

根据Steve的要求,我去了Amazon Kindle平板电脑上尝试使用Firebase版本,即使没有安装Google Play服务,它也能正常工作.

As per Steve request, i went and try the version with Firebase on my Amazon Kindle tablets and it does work even thou there's no Google Play Services installed on them.

推荐答案

按照史蒂夫的回答,即使没有Google,Firebase分析也能正常工作 播放服务.但是我们仍然可以禁用Google服务插件 口味.

As per Steve's answer Firebase analytics works even without Google play services. But we still can disable google services plugin for flavors.

尝试添加这样的代码:

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

 android.applicationVariants.all { variant ->
     if (!variant.name.contains("flavorName")) {
         project.tasks.each { t ->
             if (t.name.contains("GoogleServices")) {
                 // Remove google services plugin
                 variant.getVariantData().resourceGenTask.getTaskDependencies().values.remove(t);
                 // For latest gradle plugin use this instead
                 // variant.getVariantData().taskContainer.sourceGenTask.getTaskDependencies().getDependencies().remove(t)
             }
         }
     }
 }

在这里,我禁用了所有名称相同的Google服务 不包含"flavorName".您应该修改条件以适合 您的要求. 请注意,应该在之后添加 apply plugin: 'com.google.gms.google-services'.希望对您有所帮助.

Here I disable google services for all flavors which their name doesn't contains "flavorName". You should modify the conditions to fit your requirement. And notice that this should be added after apply plugin: 'com.google.gms.google-services'. Hope it helps.

这篇关于我可以针对特定口味禁用Firebase插件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆