我可以禁用特定风格的Firebase插件吗?

fdx2calv  于 2023-03-24  发布在  其他
关注(0)|答案(6)|浏览(116)

我目前正在尝试Firebase分析套装,但是,我遇到了一个小问题,我的应用程序在Google Play和Amazon Store上都有分发(不支持Google Play服务),所以对于Amazon风味,我想删除对Firebase的依赖(我已经知道如何做),但是,我还需要删除Firebase插件,以便它在构建时不会抛出异常。
这就是我目前所拥有的:

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'

但是,我需要删除插件只有当是亚马逊的味道.
这甚至可能吗?或者至少有什么接近的东西我可以尝试?

更新日期:

按照史蒂夫的要求,我去尝试在我的亚马逊Kindle平板电脑上使用Firebase的版本,即使没有安装Google Play服务,它也能正常工作。

myzjeezk

myzjeezk1#

根据史蒂夫的回答,Firebase分析即使没有Google Play服务也能工作。但我们仍然可以禁用Google服务插件。
尝试像这样添加代码:

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)
             }
         }
     }
 }

在这里,我禁用所有口味的谷歌服务,他们的名字不包含“flavorName”。你应该修改的条件,以满足您的要求。并注意,这应该被添加后apply plugin: 'com.google.gms.google-services'。希望它有帮助。

5w9g7ksd

5w9g7ksd2#

我终于得到了一个可以使用新Gradle的版本。测试使用Gradle 4.6,构建工具3.0.1,谷歌服务插件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
    }
}
cclgggtu

cclgggtu3#

虽然Firebase不正式支持没有Google Play服务的设备,但Analytics实际上应该在此类设备上工作,因此您实际上可能不需要在Amazon版本中禁用Firebase(或删除插件)。您尝试过吗?

2g32fytz

2g32fytz4#

由于某些Google Play服务库 * 仍然需要包含 * 在您的firebase免费版本中,因此某些firebase相关条目可能最终会出现在最终合并的AndroidManifest.xml中。
因此,如果除了删除由Google Services插件添加的gradle任务(如曹俊跃的回答中所述)之外,您还想从最终合并的AndroidManifest中删除Firebase相关的receiver,service,provider,uses-permission或其他标记,您可以将节点标记添加到位于应用程序的flavor,build config或build variant子目录中的AndroidManifest.xml。
如果节点标记被设置为“移除”,则对应的接收者、服务、提供者、使用权限标签将不存在于最终合并的AndroidManifest.xml中。
例如,以下是您可以添加到项目的假设'nofirebase'风格源目录(app/src/nofirebase/)中的AndroidManifest.xml的内容:

<receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
        tools:node="remove" />

    <receiver
        android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
        tools:node="remove" />

    <receiver
        android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
        tools:node="remove" />

    <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        tools:node="remove" >
    </receiver>

    <service
        android:name="com.google.android.gms.measurement.AppMeasurementService"
        tools:node="remove" />

    <service
        android:name="com.google.firebase.iid.FirebaseInstanceIdService"
        tools:node="remove"/>

    <provider
        android:name="com.google.firebase.provider.FirebaseInitProvider"
        android:authorities="com.you.yourapp.firebaseinitprovider"
        tools:node="remove"/>
kx5bkwkv

kx5bkwkv5#

根据上面的答案,我收到了一个错误,任务不存在(?它是在构建过程中生成的?)。对我来说,简单地要求任务自行更正。在我的情况下,我在UAT构建中禁用了Fabric。

tasks.all {

        if (it.name.contains("Uat") && (
                it.name.contains("GoogleServices") ||
                it.name.contains("fabric"))
        ){
            it.enabled = false
        }

}
avwztpqn

avwztpqn6#

我的方法是只为特定的风格(基于kotlin的gradle脚本)包含firebase:

//somewhere at beginning of app's gradle file
var includeFirebase = true

...

//at flavors section
productFlavors {
        create("foss") {
            dimension = "appstore"
            //do not include firebase in the foss build
            includeFirebase = false

...

//at the end of script
if(includeFirebase) {
    plugins {
        id("com.google.gms.google-services")
        id("com.google.firebase.crashlytics")
    }
}

相关问题