如何使用0.14+;Android Gradle插件的版本?
我想将如何使用0.14+;Android Gradle插件的版本?,android,gradle,Android,Gradle,我想将versionName包含在我的Android版本的输出APK文件的名称中 有一个插件适用于0.14.x之前的插件版本,但他们更改了一些数据模型,使其不再适用,我不知道如何修复它。就我所知,下面的代码块应该可以工作,但最后的set()调用似乎没有效果。它不会抛出错误,但也不会替换该值 buildTypes { applicationVariants.all { variant -> def oldFile = variant.outputs.outputFil
versionName
包含在我的Android版本的输出APK文件的名称中
有一个插件适用于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"))
}
}
}
我复制了你的答案,做了一些修改:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace("-assistant", "-assistant-${versionName}"))
}
}
“助手”一词在我的文件名中位于变体名称之前。例如,我有3个变体
ax、bx、cx
文件名在我的示例中:
- -assistant-ax-debug.apk
- -assistant-bx-debug.apk
- -assistant-cx-debug.apk
- -assistant-1.0-ax-debug.apk
- -assistant-1.0-bx-debug.apk
- -assistant-1.0-cx-debug.apk
希望这对您有所帮助。当您使用3.0.0版或更高版本的插件时,您必须做一些轻微的更改:
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "myapp-${variant.versionName}-${variant.name}.apk"
}
}
3.0.0插件说:
如果使用each()遍历变量对象,则需要开始使用all()。这是因为each()只遍历在配置时已经存在的对象,但这些对象在配置时不存在于新模型中。但是,all()通过在执行过程中添加对象时拾取对象来适应新模型
我收到一个错误,说它找不到applicationVarients属性。。。这就是为什么我们不喜欢格拉德尔。您必须编写代码来更改异常的输出文件名。这会在Gradle sync上产生警告:“'variantOutput.getPackageApplication()'已过时,并已替换为'variant.getPackageApplicationProvider()'”。有关解决方法,请参见: