【问题标题】:I've just upgraded gradle and I am getting a warning about an obsolete call. How to fix?我刚刚升级了 gradle,我收到了关于过时调用的警告。怎么修?
【发布时间】:2023-03-26 23:00:01
【问题描述】:

我正在使用 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", ""))
        }
    }
}

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

警告:API 'variantOutput.getPackageApplication()' 已过时并已替换为 'variant.getPackageApplicationProvider()'。 它将在 2019 年底被删除。 有关详细信息,请参阅https://d.android.com/r/tools/task-configuration-avoidance。 原因:调用自:C:\Users\my name\StudioProjects\core\app\build.gradle:26

如何重写此代码以避免警告?

【问题讨论】:

  • 您好,我也有同样的问题,您找到解决方案了吗?
  • 刚开始赏金,所以我们会看看它会带来什么。
  • 嗨。类似的问题在这里讨论:stackoverflow.com/questions/54206898/…(还没有批准的解决方案,但有解决方法和一些解释)
  • 变通办法似乎不是一个永久的解决方案,就像升级到 gradle 5.0 时会发生什么

标签: android android-studio gradle android-build


【解决方案1】:

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

butterknife 库中也发生了类似的情况。看看这些,你可能会发现一些有用的信息 Butterknife Issue 1431

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

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

【讨论】:

    【解决方案2】:

    经过大量的研发,我找到了解决方案

    我所做的是我从 android.applicationVariants.all 文件中删除了 output.zipAlign 并且警告消失了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2023-03-06
      • 2015-03-08
      • 1970-01-01
      相关资源
      最近更新 更多