此文章发布于64
个月前,部分信息可能已经过时
,请自行斟酌确认。
修改 build.gradle
增加以下代码
//自定生成 apk 文件名和生成路径
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
// 生成路径
variant.getPackageApplicationProvider().get().outputDirectory = new File("${rootDir}\\release")
// 名称+当前版本号
def fileName = "app_${defaultConfig.versionName}"
// 如果有渠道,显示渠道名""
if (variant.flavorName != "") {
fileName = fileName + "_${variant.flavorName}"
}
// 加入打包日期,如20181010
def releaseDate = new Date().format("yyyyMMdd", TimeZone.getDefault())
fileName = fileName + "_${releaseDate}"
// 如果是debug版本,加入debug
if ('debug' == variant.buildType.name) {
fileName = fileName + "_debug"
}
// 最终生成文件名
output.outputFileName = fileName + ".apk"
}
}
最终打包效果: