代码改变世界

[Android Tips] 29. 如何判断当前编译的是哪个 Flavor ?

2017-12-01 11:48  shaobin0604  阅读(2387)  评论(0编辑  收藏  举报

背景说明

应用需要针对不同的市场集成不同的第三方 SDK ,比如:面向海市场的版本需要集成 google-service apply plugin: 'com.google.gms.google-services'

解决方案


// build.gradle in application module

android {
    productFlavors {
        googlePlay {
        }
        wandoujia {
        }
    }
}

if (getGradle().getStartParameter().getTaskRequests().toString().contains("GooglePlay")) {
    // Google Play 版本才应用该插件
    apply plugin: 'com.google.gms.google-services'
}

参考