Gradle

defaultConfig {
    //版本号
    versionName = "1.0.2"
    // = 号后跟数字而非字符串
    versionCode = 2
    //定义变量,java文件中用BuildConfig.IS_DEBUG调用
    buildConfigField "boolean", "IS_DEBUG", "false"
    buildConfigField "boolean", "IS_SYSTEM_OUT", "false"
}
//打包后的apk名字,可以写在buildTypes中
applicationVariants.all { variant ->
    println(variant)
    variant.outputs.each { output ->
        def apk = output.outputFile
        def snakeVersion = defaultConfig.versionName.replace(".", "_")
        def suffix = variant.buildType.name == 'release' ? "" : '-' + variant.buildType.name
        def fileName = "xxx_" + snakeVersion + "_from_${variant.productFlavors[0].name}" + suffix + ".apk"
        output.outputFile = new File(apk.parentFile, fileName)
    }
}
//release时调用
release {
    //代码混淆
    minifyEnabled true
    //去掉为用资源
    shrinkResources true
    //代码混淆配置
    proguardFile getDefaultProguardFile('proguard-android.txt')
    proguardFile 'proguard-project.txt'
}
//debug模式,debug时不会调用release{}
debug {
    minifyEnabled true
    shrinkResources true
    proguardFile getDefaultProguardFile('proguard-android.txt')
    proguardFile 'proguard-project.txt'
    buildConfigField "boolean", "IS_DEBUG", "true"
    buildConfigField "boolean", "IS_SYSTEM_OUT", "true"
}

productFlavors {
    //渠道配置,AndroidManifest.xml中可以用${UMENG_CHANNEL_VALUE}
    /*eg:
        <meta-data
            android:name="UMENG_CHANNEL"
            android:value="${UMENG_CHANNEL_VALUE}"/>
     */
    dev {
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "dev"]
    }
}



你可能感兴趣的:(android,gradle)