我有這個代碼在我的build.gradle重命名德apk,但自從Android Studio更新到版本2.2不再工作。Android Studio 2.2重命名apk文件
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名稱是否可以,並且我沒有發現問題。你們是否知道任何替代方案來實現這一目標?我會永遠感激。
嘗試android.useOldPackaging =真。 https://developer.android.com/studio/releases/gradle-plugin.html#revisions – Veener