Gradle 警告:variant.getOutputFile() 和 variant.setOutputFile() 已弃用 [英] Gradle warning: variant.getOutputFile() and variant.setOutputFile() are deprecated
本文介绍了Gradle 警告:variant.getOutputFile() 和 variant.setOutputFile() 已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Android 应用程序项目中使用以下简化配置.
I am using the following simplified configuration in an Android application project.
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0.0"
applicationVariants.all { variant ->
def file = variant.outputFile
def fileName = file.name.replace(".apk", "-" + versionName + ".apk")
variant.outputFile = new File(file.parent, fileName)
}
}
}
现在我将 Gradle 插件更新到 v.0.13.0,将 Gradle 更新到 v.2.1.出现以下警告:
Now that I updated the Gradle plug-in to v.0.13.0 and Gradle to v.2.1. the following warnings appear:
WARNING [Project: :MyApp] variant.getOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.setOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.getOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.setOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
如何重写 Groovy 脚本以消除弃用警告?
How can I rewrite the Groovy script to get rid of the deprecation warnings?
推荐答案
基于 Larry Schiefer 的答案,您可以将脚本更改为如下所示:
Building on the answer from Larry Schiefer you can change the script to something like this:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = outputFile.name.replace('.apk', "-${versionName}.apk")
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
这篇关于Gradle 警告:variant.getOutputFile() 和 variant.setOutputFile() 已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文