Can I disable the Firebase plugin for a specific taste?

I am currently testing a Firebase analytics suit, but I am faced with one small problem, my application is distributed both in google play and in the amazon store (which does not support Google Play services), so for the Amazon flavor I want to remove the dependency on Firebase ( I already know how to do this), but I also need to remove the Firebase plugin so that it does not throw an exception when creating.

This is what I have 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 it is an Amazon flavor.

Is it possible? Or at least there is something close that I can try?

UPDATE:

As per Steve’s request, I went and tried the Firebase version on my Amazon Kindle tablets, and it works even where Google Play services are not installed on them.

+5
source share
4 answers

According to Steve's answer, Firebase Analytics works even without Google gaming services. But we can still disable the google services plugin for flavorings.

Try adding the following code:

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

Here I disable google services for all flavors whose names do not contain "flavorName". You must change the conditions to suit your requirements. And note that this should be added after apply plugin: 'com.google.gms.google-services' . Hope this helps.

+7
source

Although Firebase does not officially support devices without Google Play services, in fact, Google Analytics should work on such devices, and you do not need to actually disable Firebase (or remove the plugin) in your Amazon build. Have you tried it yet?

+1
source
Perhaps due to the fact that some Google Play Services libraries still need to be included in your flavor without using firebase, some firebase related entries fall into the final merged AndroidManifest.xml.

So, if in addition to removing the gradle tasks that were added by the Google Services plugin (as described in Junyue Cao's answer), you want to remove the recipient, service, provider, use-use or other use of Firebase tags from the final unified AndroidManifest, you can add node markers in AndroidManifest.xml located in the application, create a configuration or create a subdirectory option.

If the node tokens are set to β€œdelete”, then the corresponding final AndroidManifest.xml will not contain the corresponding receiver tags, services, provider, use-permission tags.

For example, here is what you could add to AndroidManifest.xml in a hypothetical design source for the flavor source 'nofirebase' (app / src / nofirebase /):

  <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"/> 
0
source

I finally got a version to work with the new gradle. Tested with gradle 4.6, build tools 3.0.1, google-services 3.1.1 plugin

  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
     }
 }
0
source

All Articles