Android Studio: How to exclude google-services module in product flavor?

后端 未结 3 1411
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 18:58

In my Android project, there are several product flavors:

buildTypes {
    release {}
    debug {}
    staging {}
}

productFlavors {
    freeVersion {}
             


        
3条回答
  •  难免孤独
    2021-01-17 19:38

    Another solution is to disable the task the google-services plugin adds - here I enable the task if the flavorName is not "freeVersion" but this logic can clearly be updated to say look at the variants buildType instead.

    apply plugin: 'com.google.gms.google-services'
    
    // must be after the plugin is applied otherwise no tasks will be found
    android.applicationVariants.all { variant ->
        def googleTask = tasks.findByName("process${variant.name.capitalize()}GoogleServices")
        googleTask.enabled = !"freeVersion".equals(variant.flavorName)
    }
    

提交回复
热议问题