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

后端 未结 3 1271
没有蜡笔的小新
没有蜡笔的小新 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:45

    Please notice the use of freeCompile and declaring a variable flavor to conditionally apply the plugin.

    apply plugin: 'com.android.application'
    
    def flavor
    
    android {
    
        ....
    
        ....
    
        productFlavors {
            free {
                applicationId "com.anandbibek.builditbigger.free"
                flavor = "free"
            }
            paid {
                applicationId "com.anandbibek.builditbigger.paid"
                flavor = "paid"
            }
        }
    }
    
    dependencies {
    
        // Added for AdMob
        freeCompile 'com.google.firebase:firebase-ads:9.6.1'
    
        compile 'com.android.support:appcompat-v7:24.2.1'
        compile 'com.google.code.findbugs:jsr305:2.0.1'
    
    }
    if(flavor == "free") {
        apply plugin: 'com.google.gms.google-services'
    }
    

    Make sure you put the google-services.json file in flavor specific folder. In my case, I put that in app/src/free only . This facility is available when you use classpath 'com.google.gms:google-services:3.0.0' in your main project gradle file.

提交回复
热议问题