我想要在我的Android版本中包含输出APK文件名称中的versionName
。如何使用0.14+版本的Android Gradle插件向我的APK文件添加版本号?
有一个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)
}
有人可以帮我解决这个问题吗?
我得到一个错误,说它无法找到applicationVarients属性 – jonney 2015-04-07 11:03:17
...这就是我们不喜欢gradle的原因。你必须编写代码来改变怪异的输出文件名。 – 2015-07-02 20:51:22