Android打包重命名apk文件

在主项目里的build.gradle中添加
//用于下面添加时间到命名中的方法
def releaseTime() {
    //GMT+8是因为北京时间和GMT有8个小时时差。
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("GMT+8"))
}

//在android{}中添加
applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = "我的自定义命名_v${defaultConfig.versionName}_${variant.name}_${releaseTime()}.apk"
                outputFileName = fileName
            }
        }
    }
```Android
最后打包完后apk文件名为我的自定义命名_v1.0_release_2018_11_21.apk

你可能感兴趣的:(Android打包重命名apk文件)