配置打包后生成apk名字

为了方便区分apk版本等等信息…我们在配置下生成APK的名字,只需在module/build.gradle文件下添加如下配置

def packageTime() {    
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
} 
android {   
 //........    
applicationVariants.all { variant ->        variant.outputs.each { output ->            def outputFile = output.outputFile            if (outputFile != null && outputFile.name.endsWith('.apk')) {                File outputDirectory = new File(outputFile.parent);                def fileName                if (variant.buildType.name == "release") {                    fileName = "app_v${defaultConfig.versionName}_${packageTime()}_${variant.productFlavors[0].name}_release.apk"                } else if(variant.buildType.name == "debug") {                    fileName = "app_v${defaultConfig.versionName}_${packageTime()}_${variant.productFlavors[0].name}_beta.apk"                }                output.outputFile = new File(outputDirectory, fileName)            }        }    }}



原文: https://blog.csdn.net/u013278099/article/details/50463577

你可能感兴趣的:(配置打包后生成apk名字)