mic*_*ohl 6 android lint kotlin
我正在尝试实现自定义 lint 检查(使用 Kotlin)。我已经为我的自定义检查设置了一个模块并添加了类来测试我的第一个 lew lint 检查,主要是在这里和这里遵循这两个教程。
所以我现在有一个模块,我有一个自定义的 IssueRegistry,我已经为它创建了一个问题和一个 Detector 类。到目前为止,它似乎是完整的。我添加了一个测试来检查我的 lint 检查是否有效并且看起来没问题。
我通过在 settings.gradle 中引用它来将我的模块添加到项目中,如下所示: include ':app', ':somemodule', ':mylintmodule'
现在,如果我使用 linter 运行 linter,./gradlew lint我会得到一个 lint 结果文件,告诉我:
Lint found an issue registry (com.myproject.mylintmodule) which requires a newer API level. That means that the custom lint checks are intended for a newer lint version; please upgrade
Lint can be extended with "custom checks": additional checks implemented by developers and libraries to for example enforce specific API usages required by a library or a company coding style guideline.
The Lint APIs are not yet stable, so these checks may either cause a performance degradation, or stop working, or provide wrong results.
This warning flags custom lint checks that are found to be using obsolete APIs and will need to be updated to run in the current lint environment.
It may also flag issues found to be using a newer version of the API, meaning that you need to use a newer version of lint (or Android Studio or Gradle plugin etc) to work with these checks.
To suppress this error, use the issue id "ObsoleteLintCustomCheck" as explained in the Suppressing Warnings and Errors section.
Run Code Online (Sandbox Code Playgroud)
所以它告诉我我在我的自定义 lint 检查中使用了更新的 API 版本,对吗?这是我的自定义 IssueRegistry(减去一些与此问题无关的部分):
class MyCustomIssueRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(ISSUE_NAMING_PATTERN)
override val api: Int = com.android.tools.lint.detector.api.CURRENT_API
override val minApi: Int = 1
}
Run Code Online (Sandbox Code Playgroud)
通过谷歌搜索这个问题并找到这个问题,我想我必须像上面那样覆盖这些属性来覆盖和设置正确的 API 版本(也许是最小 API?)(这个版本是我最后一次尝试,直接取自那个问题) . 所以这个属性可以设置为 -1 到 5 之间的值,这意味着(直接从 lint.detector.api 类中取出):
/** Describes the given API level */
fun describeApi(api: Int): String {
return when (api) {
5 -> "3.5+" // 3.5.0-alpha07
4 -> "3.4" // 3.4.0-alpha03
3 -> "3.3" // 3.3.0-alpha12
2 -> "3.2" // 3.2.0-alpha07
1 -> "3.1" // Initial; 3.1.0-alpha4
0 -> "3.0 and older"
-1 -> "Not specified"
else -> "Future: $api"
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有这些,再加上上面添加了 minApi 覆盖的那个,并且我一直为他们每个人获得完全相同的结果。
此外,我无法找到与之比较的其他 API 版本。在 Android 项目中是否有为常规 linter 设置的地方?
我也不清楚我必须做什么来确保我的更改得到应用 - 更改一些代码,然后运行 lint 是否足够,或者我必须先编译项目,还是构建和清理?
按照教程,我通过将其添加到应用程序的 build.gradle 中来添加我的自定义 lint 检查:lintChecks project(":mylintmodule")
是这样吗?无论我的 lint 检查是否被引用(并希望被使用),我的注册表类上的 API 问题都会出现。我还尝试了第一个教程中描述的其他方法,将此任务添加到 linter 模块 build.gradle 中:
defaultTasks 'assemble'
task copyLintJar(type: Copy) {
description = 'Copies the lint jar file into the {user.home}/.android/lint folder.'
from('build/libs/')
into(System.getProperty("user.home") + '/.android/lint')
include("*.jar")
}
// Runs the copyLintJar task after build has completed.
build.finalizedBy(copyLintJar)
Run Code Online (Sandbox Code Playgroud)
但由于我不知道如何查看我的自定义检查是否实际运行,我也不知道这是否按预期工作。
那么如何解决此警告(因为我将文本解释为“只要版本不匹配,我就不会尝试运行您的 lint 检查”),以及如何确保我的 lint 检查实际上是由棉绒?
| 归档时间: |
|
| 查看次数: |
1791 次 |
| 最近记录: |