gradle 打生产开发两种包

来源:互联网 发布:java中的类 编辑:程序博客网 时间:2024/05/16 12:02

gradle android 标签下

productFlavors{    测试版 {        resValue "string", "app_name", "测试版应用名"        resValue "bool", "isrRank", 'true'        applicationIdSuffix ".debug"   //不同包名 可以同时安装 两个版本         buildConfigField("boolean", "IS_DEBUG", "true")//生产环境    }    正式版 {        resValue "string", "app_name", "正式版应用名"        resValue "bool", "isrRank", 'true'        buildConfigField("boolean", "IS_DEBUG", "false")//非生产    }}
buildTypes {    release {        minifyEnabled false        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'        debuggable true        signingConfig signingConfigs.release        applicationVariants.all { variant ->            variant.outputs.each { output ->                def outputFile = output.outputFile                if (outputFile != null && outputFile.name.endsWith('.apk')) {                    def fileName = "输出名_${variant.flavorName}_v${variant.versionName}_${getTime()}.apk"                    output.outputFile = new File("输出目录"+getDay(), fileName)                }            }        }    }    debug {        minifyEnabled false        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'        debuggable true        signingConfig signingConfigs.release    }}


def getDay() {    def date = new Date()    def formattedDate = date.format('yyyyMMdd')    return formattedDate}def getTime() {    def date = new Date()    def formattedDate = date.format('HHmmss')    return formattedDate}
public class App extends Application {    private static boolean IsDebug=BuildConfig.IS_DEBUG;//Application 获取布尔值来控制开发生产}


0 0
原创粉丝点击