当targetSdkVersion设置为29时,Android Lint报告OldTargetApi。

6
我在Github Actions(项目的当前CI解决方案)上遇到了以下Lint错误。
 > 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)
                           ~~

我的targetSdkVersion已经设置为29了。

enter image description here

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

enter image description here

一些本地环境数据:

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

对于这个被认为是“安全”的构建,为什么会产生不同的输出呢?有什么想法吗?


你可以禁用代码检查吗? - Shalu T D
当然我可以。但那并不能解决问题。我不愿意妥协质量,因此提出这个问题。 - Robert Estivill
好的,我明白。 - Shalu T D
2
又发生了,但现在是使用 SDK 30... - Dmytro Karataiev
2个回答

4

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

在你的app文件夹中创建一个lint.xml文件,并列出你要忽略lint检查的build.gradle文件:

<lint>
    <issue id="OldTargetApi">
        <ignore path="build.gradle"/>
    </issue>
</lint>

1
你不喜欢Android吗?现在使用SDK 32就可以了 :) - Dmytro Karataiev

1

这是在将Android构建工具链更新到最新版本后发生的情况。很可能你的CI运行实例被设置为始终下载最新的工具。一旦安装了构建工具链的下一个版本,它就期望你针对该版本的Android API进行目标定位。

因此,解决方案就是在你的lint.xml中添加对OldTargetAPI的忽略,就像@dmytro-karataiev提到的那样,或者在准备好定位最新的Android API之前不要更新你的构建工具链。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接