android - 我刚刚升级了 gradle,我收到有关过时调用的警告。怎么修?

标签 android android-studio gradle android-build

我使用的是 gradle 插件版本 3.3.0,我的 gradle 包装器使用的是 distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

我在我的 app/build.gradle 文件中使用以下代码:

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def apk = output.outputFile //happens here (line 26)
        def newName

        if (variant.buildType.name == "release") {
            newName = "ediary.apk"
        } else {
            newName = "ediary-debug.apk"
        }

        output.outputFileName = new File(
                "./build/",
                output.outputFile.name)

        if (output.zipAlign) {
            output.outputFileName = new File(
                    "./build/",
                    newName.replace("-unaligned", ""))
        }
    }
}

项目已构建,但我收到此警告:

WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'. It will be removed at the end of 2019. For more information, see https://d.android.com/r/tools/task-configuration-avoidance. REASON: Called from: C:\Users\my name\StudioProjects\core\app\build.gradle:26

我如何重写它以避免警告?

最佳答案

这是 android 构建工具 3.3.0 中记录的更改。 (我不确定 gradle 4.10 及更高版本)我不是 gradle 专家或类似专家,但是,我很确定您在上面共享的代码不会导致此警告。它可能是您的依赖项之一,它正在使用现在已弃用的警告中提到的 API。如果您想继续使用 Android 构建工具 3.3.0,唯一的解决方法是暂时关闭警告。

类似的案例也发生在butterknife图书馆。看看这些,你可能会找到一些有用的信息 Butterknife Issue 1431

我个人正在关闭此警告并继续前进。只需在 gradle.properties 中添加以下行

android.jetifier.blacklist = butterknife-compiler //replace with possible artifact name

关于android - 我刚刚升级了 gradle,我收到有关过时调用的警告。怎么修?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54191577/

相关文章:

spring - 使用 kotlin-spring 插件,仍然得到 class not open 错误

java - 如何使用 onDraw 在每个矩形的中心显示文本

android - 使用 gradle 构建库项目时,BuildConfig.DEBUG 始终为 false

android - 用图标填充多边形

java - 如何在警报对话框中保存多选状态?

Android Studio 的项目 gradle 文件变了?

android - Gradle 配置不再适用于 Android Studio 3(测试版)

java - Lottie - setProgress 无法正常工作

android - 构建apk时出错

Android Q - 未经批准连接wifi