我在build.gradle中有此代码可重命名de apk,但由于Android Studio更新至2.2版不再有效。
apply plugin: 'com.android.application'
def getDate() {
def date = new Date()
def formattedDate = date.format('yyMMdd')
return formattedDate
}
def gitBranch() {
def branch = ""
def proc = "git rev-parse --abbrev-ref HEAD".execute()
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
branch
}
android {
// defaultConfig, buildTypes, etc.
android.applicationVariants.all { variant ->
def versionName = variant.versionName.replaceAll('\\.', '_')
def date = getDate()
def versionCode = variant.versionCode
def branch = gitBranch()
variant.outputs.each { output ->
def newApkName
if (output.zipAlign) {
newApkName = "APP${versionName}D${date}VC${versionCode}-${branch}.apk"
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
}
}
我添加了一些println来查看newApk名称是否正确,并且没有问题。各位,您知道其他替代方法吗?我将永远感激不已。
最佳答案
通过采用新的默认打包管道来处理一项任务中的压缩,签名和zipaligning,从而提高构建性能。您可以通过将android.useOldPackaging = true添加到yourgradle.properties文件来恢复使用较旧的打包工具。使用新的打包工具时,zipalignDebug任务不可用。但是,您可以通过调用createZipAlignTask(String taskName,File inputFile,File outputFile)方法来自己创建一个。
从发行说明中:
https://developer.android.com/studio/releases/gradle-plugin.html#revisions
关于android - Android Studio 2.2重命名apk文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39605852/