当 targetSdkVersion 为 29 时,Android Lint 报告 OldTargetApi

Rob*_*ill 6 android android-lint android-gradle-plugin

我在 Github Actions 上收到以下 Lint 错误(该项目的当前 CI 解决方案)

 > Task :application:lint FAILED
Ran lint on variant debug: 1 issues found
Ran lint on variant release: 1 issues found
Wrote HTML report to file:///~/application/build/reports/lint/lint-results.html

64 actionable tasks: 55 executed, 9 from cache
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':application:lint'.
> Lint found errors in the project; aborting build.

android {
    lintOptions {
        abortOnError false
    }
}
...
Errors found:
  
~/application/build.gradle.kts:17: Error: Not targeting the latest versions of Android; compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details. [OldTargetApi]
          targetSdkVersion(29)
                           ~~
Run Code Online (Sandbox Code Playgroud)

我的已经targetSdkVersion设置好了29

在此输入图像描述

如果我在本地运行完全相同的命令 ( ./gradlew build),则不会报告 lint 错误。

在此输入图像描述

一些本地环境数据:

  • Gradle 包装器 6.5
  • Android Gradle插件4.1.0-beta02
  • 科特林 1.3.72
  • JDK 1.8.0_242

关于为什么这个所谓的“包含”构建会导致不同的输出有什么想法吗?

Dmy*_*iev 4

这不是一个正确的解决方案,如果您不想禁用 lint 检查,这只是一个临时解决方法。

在您的文件夹中创建一个lint.xml文件app并列出要被 lint 忽略的 build.gradle 文件:

<lint>
    <issue id="OldTargetApi">
        <ignore path="build.gradle"/>
    </issue>
</lint>
Run Code Online (Sandbox Code Playgroud)