Can i disable Firebase plugin for specific flavor?

前端 未结 5 1972
执笔经年
执笔经年 2021-02-13 03:01

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 goog

相关标签:
5条回答
  • 2021-02-13 03:27

    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.

    0 讨论(0)
  • 2021-02-13 03:29

    With answers above I was receiving an error that task doesn't exist (?it was generated during build?). What worked for me was to simply ask tasks to correct themselves. In my case I was disabling Fabric on UAT builds.

    tasks.all {
    
            if (it.name.contains("Uat") && (
                    it.name.contains("GoogleServices") ||
                    it.name.contains("fabric"))
            ){
                it.enabled = false
            }
    
    }
    
    0 讨论(0)
  • 2021-02-13 03:33

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

    0 讨论(0)
  • 2021-02-13 03:34

    It's possible that, because some Google Play Services libraries still need to be included in your firebase-free flavor, that some firebase related entries end up in the final merged AndroidManifest.xml.

    So, if, in addition to removing the gradle tasks which were added by the Google Services plugin (as described in Junyue Cao's answer), you want to remove Firebase related receiver, service, provider, uses-permission or other tags from the final merged AndroidManifest, you can add node markers to the AndroidManifest.xml located in the app's flavor, build config, or build variant subdirectory.

    If the node markers are set to "remove", then the corresponding receiver, service, provider, uses-permission tags will not be present in the final merged AndroidManifest.xml.

    For example, here's what you might add to the AndroidManifest.xml in a project's hypothetical 'nofirebase' flavor source dir (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 讨论(0)
  • 2021-02-13 03:53

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题