zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

【Android Gradle 插件】LintOptions 配置 ② ( abortOnError 配置 | 手动执行 lint 检查并生成 lint-result.html 检查报告 )

2023-06-13 09:18:05 时间

文章目录

Android Plugin DSL Reference 参考文档 :

一、LintOptions#abortOnError 配置


LintOptions ( build.gradle#android#lintOptions ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.LintOptions.html

1、配置简介

LintOptions#abortOnError 配置 用于设置 当编译时遇到错误 是否需要退出 ;

  • 设置 true , 则遇到错误后 , 就会退出编译 ;
  • 设置 false, 则遇到错误后 , 继续进行编译 ;

2、配置原型

LintOptions#abortOnError 配置原型 : 该配置是 布尔值类型的 ;

boolean abortOnError
Whether lint should set the exit code of the process if errors are found

3、使用示例

LintOptions#abortOnError 配置使用示例 :

android {
    lintOptions {
        // 编译时遇到错误, 停止编译
        abortOnError true
    }
}

二、手动执行 lint 检查


1、执行 lint 检查命令

在 Android Studio 中的 执行

gradlew :app:lintDebug

命令 , 执行 lint 检查 , 命令行输出 :

Y:\002_WorkSpace\001_AS\SVG>gradlew :app:lintDebug

> Task :app:compileDebugKotlin
w: Y:\002_WorkSpace\001_AS\SVG\app\src\main\java\kim\hsl\svg\MainActivity.kt: (16, 44): 'getDrawable(Int): Drawable!' is deprecated. Deprecated in Java

> Task :app:lintDebug
Wrote HTML report to file:///Y:/002_WorkSpace/001_AS/SVG/app/build/reports/lint-results-debug.html
Wrote XML report to file:///Y:/002_WorkSpace/001_AS/SVG/app/build/reports/lint-results-debug.xml

BUILD SUCCESSFUL in 1m 2s
18 actionable tasks: 3 executed, 15 up-to-date

2、查看生成的 lint 检查报告

根据输出日志 ,

> Task :app:lintDebug
Wrote HTML report to file:///Y:/002_WorkSpace/001_AS/SVG/app/build/reports/lint-results-debug.html
Wrote XML report to file:///Y:/002_WorkSpace/001_AS/SVG/app/build/reports/lint-results-debug.xml

最终生成的 lint 检查报告输出在 Y:/002_WorkSpace/001_AS/SVG/app/build/reports/lint-results-debug.html 路径中 , 使用 浏览器打开该 html 页面 ;