Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i disable Firebase plugin for specific flavor?

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.

This is what i have as far now:

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 ?

UPDATE:

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.

like image 226
Jorge Aguilar Avatar asked Jun 08 '16 05:06

Jorge Aguilar


People also ask

What is firebase disabled?

A disabled user cannot sign in to an app anymore and continues to be stored in the Firebase Auth backend. You have the ability to disable/enable a user via the admin SDK or from the firebase console.

How do I turn off firebase Analytics?

If you need to deactivate Analytics collection permanently in a version of your app, set FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to YES (Boolean) in your app's Info.

How to turn off performance monitoring in Firebase?

You can build your app with the Performance Monitoring SDK enabled but have the option to disable it at runtime using Firebase Remote Config. You can completely deactivate the Performance Monitoring SDK, with no option to enable it at runtime.

How do I disable Firebase Analytics collection?

If you wish to temporarily disable Analytics collection, such as to get end-user consent before collecting data, you can set the value of FIREBASE_ANALYTICS_COLLECTION_ENABLED to NO (Boolean) in your app's Info.plist file. For example, viewed in the source XML:

Is it possible to use firebase on macOS?

Note: This Firebase product is not available on the macOS target. Note: This Firebase product is not available on the macOS target. If you need to suspend collection again for any reason, you can call Note: This Firebase product is not available on the macOS target. and collection is suspended until you re-enable it.

What happens if I set Firebase_Analytics_collection_deactivated to no (Boolean)?

Setting FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED to NO (Boolean) has no effect and results in the same behavior as not having FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED set in your Info.plist file.


2 Answers

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

Try add code like this:

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

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.

like image 165
Junyue Cao Avatar answered Sep 30 '22 04:09

Junyue Cao


I finally got a version to work with new gradle. Tested with gradle 4.6, build tools 3.0.1, google-services plugin 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
    }
}
like image 21
Jack Feng Avatar answered Sep 30 '22 04:09

Jack Feng