gpt4 book ai didi

android - Gradle 警告 : variant. getOutputFile() 和 variant.setOutputFile() 已弃用

转载 作者:IT老高 更新时间:2023-10-28 21:42:23 29 4
gpt4 key购买 nike

我在一个 Android 应用程序项目中使用以下简化配置。

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。出现以下警告:

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 脚本以消除弃用警告?

最佳答案

Larry Schiefer 的回答为基础您可以将脚本更改为以下内容:

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)
}
}
}
}

关于android - Gradle 警告 : variant. getOutputFile() 和 variant.setOutputFile() 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25997866/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com