【Android Gradle 插件】LintOptions 配置 ① ( BaseExtension#lintOptions 配置 | LintOptions 配置简介 | lint 工具 )

2023-03-30 15:24:42 浏览数 (2)

文章目录

  • 一、BaseExtension#lintOptions 配置
    • 1、BaseExtension#lintOptions { } 脚配块配置简介
    • 2、BaseExtension#lintOptions { } 脚配块配置原型
    • 3、BaseExtension#lintOptions 属性配置原型
  • 二、LintOptions 配置简介

Android Plugin DSL Reference 参考文档 :

  • 文档主页 : https://google.github.io/android-gradle-dsl/2.3/
  • BaseExtension 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.BaseExtension.html
  • AppExtension ( build.gradle#android 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.AppExtension.html
  • build.gradle#android 模块配置文档 : android-gradle-dsl/2.3/com.android.build.gradle.AppExtension.html
  • ProductFlavor ( build.gradle#android#defaultConfig 配置 ) 文档 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.ProductFlavor.html
  • ProductFlavor#externalNativeBuild 配置 ( build.gradle#android#defaultConfig#externalNativeBuild 配置 ) : com.android.build.gradle.internal.dsl.ProductFlavor:externalNativeBuild
  • ExternalNativeBuildOptions ( build.gradle#android#defaultConfig#externalNativeBuild 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.ExternalNativeBuildOptions.html
  • NdkBuildOptions ( build.gradle#android#defaultConfig#externalNativeBuild#ndkBuild 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.NdkBuildOptions.html
  • CmakeOptions ( build.gradle#android#defaultConfig#externalNativeBuild#cmake 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.CmakeOptions.html
  • JackOptions ( build.gradle#android#defaultConfig#jackOptions 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.JackOptions.html
  • AnnotationProcessorOptions ( 注解处理器配置 ) ( build.gradle#android#defaultConfig#javaCompileOptions配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AnnotationProcessorOptions.html
  • NdkOptions ( build.gradle#android#defaultConfig#ndk 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.NdkOptions.html
  • VectorDrawablesOptions ( build.gradle#android#defaultConfig#vectorDrawables 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.VectorDrawablesOptions.html
  • BuildType ( build.gradle#android#buildTypes 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.BuildType.html
  • SigningConfig ( build.gradle#android#signingConfigs 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.SigningConfig.html
  • AaptOptions ( build.gradle#android#aaptOptions 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AaptOptions.html
  • AndroidSourceSets ( build.gradle#android#sourceSets 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.api.AndroidSourceSet.html
  • AndroidSourceDirectorySet ( build.gradle#android#sourceSets#aidl/assets/java/jni/jniLibs 配置 ) 文档位置 :android-gradle-dsl/2.3/com.android.build.gradle.api.AndroidSourceDirectorySet.html
  • AndroidSourceFile ( build.gradle#android#sourceSets#manifest 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.api.AndroidSourceFile.html
  • DataBindingOptions ( build.gradle#android#dataBinding ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.DataBindingOptions.html
  • DexOptions ( build.gradle#android#dexOptions ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.DexOptions.html
  • LintOptions ( build.gradle#android#lintOptions ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.LintOptions.html
  • NDK 参考文档 : Add C and C Code to Your Project.

一、BaseExtension#lintOptions 配置


BaseExtension 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.BaseExtension.html

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

1、BaseExtension#lintOptions { } 脚配块配置简介

BaseExtension#lintOptions { } 脚配块配置 用于配置 lint 选项 ;

该脚本块主要是设置 BaseExtension 中的 LintOptions lintOptions 属性 ;

2、BaseExtension#lintOptions { } 脚配块配置原型

BaseExtension#lintOptions { } 脚配块配置原型 :

代码语言:javascript复制
lintOptions { }
Configures lint options.

Delegates to:
LintOptions from lintOptions
packagingOptions { }

3、BaseExtension#lintOptions 属性配置原型

BaseExtension#lintOptions 属性配置原型 : BaseExtension#lintOptions 属性是 LintOptions 类型的 ;

代码语言:javascript复制
LintOptions lintOptions
Lint options.

二、LintOptions 配置简介


LintOptions 配置是用于 配置 lint 工具的 ;

lint 工具的作用是帮助开发者 优化代码结构质量 , 如检查未使用的变量等 , 发现的问题可能不影响使用 , 但是可以优化代码结构 ;

lint 工具在 SDK 中的 toolsbin 目录中 ;

执行

代码语言:javascript复制
lint --help

命令 , 可以打印出 lint 工具的帮助文档 , 完整命令行输出如下 :

代码语言:javascript复制
D:01_Develop01_SDKSdktoolsbin>lint --help
Usage: lint [flags] <project directories>

Flags:

--help                           This message.
--help <topic>                   Help on the given topic, such as "suppress".
--list                           List the available issue id's and exit.
--version                        Output version information and exit.
--exitcode                       Set the exit code to 1 if errors are found.
--show                           List available issues along with full
                                 explanations.
--show <ids>                     Show full explanations for the given list of
                                 issue id's.

Enabled Checks:
--disable <list>                 Disable the list of categories or specific
                                 issue id's. The list should be a
                                 comma-separated list of issue id's or
                                 categories.
--enable <list>                  Enable the specific list of issues. This
                                 checks all the default issues plus the
                                 specifically enabled issues. The list should
                                 be a comma-separated list of issue id's or
                                 categories.
--check <list>                   Only check the specific list of issues. This
                                 will disable everything and re-enable the
                                 given list of issues. The list should be a
                                 comma-separated list of issue id's or
                                 categories.
-w, --nowarn                     Only check for errors (ignore warnings)
-Wall                            Check all warnings, including those off by
                                 default
-Werror                          Treat all warnings as errors
--config <filename>              Use the given configuration file to determine
                                 whether issues are enabled or disabled. If a
                                 project contains a lint.xml file, then this
                                 config file will be used as a fallback.
--baseline                       Use (or create) the given baseline file to
                                 filter out known issues.

Output Options:
--quiet                          Don't show progress.
--fullpath                       Use full paths in the error output.
--showall                        Do not truncate long messages, lists of
                                 alternate locations, etc.
--nolines                        Do not include the source file lines with
                                 errors in the output. By default, the error
                                 output includes snippets of source code on
                                 the line containing the error, but this flag
                                 turns it off.
--html <filename>                Create an HTML report instead. If the
                                 filename is a directory (or a new filename
                                 without an extension), lint will create a
                                 separate report for each scanned project.
--url filepath=url               Add links to HTML report, replacing local
                                 path prefixes with url prefix. The mapping
                                 can be a comma-separated list of path
                                 prefixes to corresponding URL prefixes, such
                                 as
                                 C:tempProj1=http://buildserver/sources/temp
                                 /Proj1.  To turn off linking to files, use
                                 --url none
--simplehtml <filename>          Create a simple HTML report
--xml <filename>                 Create an XML report instead.

Project Options:
--project <file>                 Use the given project layout descriptor file
                                 to describe the set of available sources,
                                 resources and libraries. Used to drive lint
                                 with build systems not natively integrated
                                 with lint.
--resources <dir>                Add the given folder (or path) as a resource
                                 directory for the project. Only valid when
                                 running lint on a single project.
--sources <dir>                  Add the given folder (or path) as a source
                                 directory for the project. Only valid when
                                 running lint on a single project.
--classpath <dir>                Add the given folder (or jar file, or path)
                                 as a class directory for the project. Only
                                 valid when running lint on a single project.
--libraries <dir>                Add the given folder (or jar file, or path)
                                 as a class library for the project. Only
                                 valid when running lint on a single project.
--compile-sdk-version <version>  Use the given compileSdkVersion to pick an
                                 SDK target to resolve Android API call to
--sdk-home <dir>                 Use the given SDK instead of attempting to
                                 find it relative to the lint installation or
                                 via $ANDROID_HOME

Exit Status:
0                                Success.
1                                Lint errors detected.
2                                Lint usage.
3                                Cannot clobber existing file.
4                                Lint help.
5                                Invalid command-line argument.

D:01_Develop01_SDKSdktoolsbin>

0 人点赞