我想在我的 Android 构建的输出 APK 文件的名称中包含 versionName
。
有一个 another answer它适用于 0.14.x 之前的插件版本,但他们更改了一些数据模型,因此它不再起作用,我不知道如何修复它。据我所知,下面的代码块应该可以工作,但最后一个 set()
调用似乎没有效果。它不会引发错误,但该值也不会被替换。
buildTypes {
applicationVariants.all { variant ->
def oldFile = variant.outputs.outputFile.get(0)
def newFile = new File(
oldFile.parent,
oldFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
variant.outputs.outputFile.set(0, newFile)
}
有人可以帮我解决这个问题吗?
最佳答案
现在每个变体都可以有多个输出,你还需要一个循环:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
}
}
}
关于android - 如何使用 0.14+ 版本的 Android Gradle 插件向我的 APK 文件添加版本号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27068505/