安卓 打包apk自动命名

方法1:

applicationVariants.all { variant ->
        variant.outputs.all { output ->  // each 改为 all
            def fileName = "ssp${variant.versionName}.apk"
            def outFile = output.outputFile
            if (outFile != null && outFile.name.endsWith('.apk')) {
                outputFileName = fileName  //  output.outputFile 改为 outputFileName
            }
        }
    }

方法2:

def releaseTime() {
    return new Date().format("yyyy.MM.dd", TimeZone.getTimeZone("UTC"))
}
applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        // 输出apk名称为appname-1.0-beta1-xxxx-xx-xx.apk
                        def fileName = "TW情景互动Unity-${defaultConfig.versionName}-beta1-${releaseTime()}.apk"
                        output.outputFile = new File(outputFile.parent, fileName)
                    }
                }
            }

 

你可能感兴趣的:(安卓)