实现代码
buildTypes {
// ...
applicationVariants.all {
variant ->
variant.outputs.all {
Calendar calendar = Calendar.getInstance(Locale.CHINA);
def buildDate = String.format(Locale.CHINA, "%04d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH))
def versionName = variant.versionName
def versionCode = variant.versionCode
//项目名-版本名-版本号-release/debug.apk
if (variant.buildType.name.equals('release')) {
variant.getPackageApplication().outputDirectory = new File("ApkOutputs/release")
outputFileName = "${rootProject.getName()}-v${versionName}-${versionCode}-${buildDate}-release.apk"
} else {
variant.getPackageApplication().outputDirectory = new File("ApkOutputs/debug")
outputFileName = "${rootProject.getName()}-v${versionName}-${versionCode}-${buildDate}-debug.apk"
}
}
}
}