【问题标题】:Android custom lint rule does not detect any issue (for imports)Android 自定义 lint 规则未检测到任何问题(对于导入)
【发布时间】:2019-12-17 05:48:53
【问题描述】:

我正在将以下 lint 项目应用于存在问题但未检测到问题的应用模块。

lintChecks project(':customlint')

ImportsIssueRegistry.kt

class ImportsIssueRegistry : IssueRegistry() {
    override val issues: List<Issue>
        get() = listOf(
            SyntheticImportIssue.ISSUE,
            AndroidLogImportIssue.ISSUE
        )

    override val api: Int
        get() = CURRENT_API
}

customlint/build.gradle

apply plugin: 'java-library'
apply plugin: 'kotlin'


ext.lintVersion = '26.4.2'

dependencies {

    //noinspection DifferentStdlibGradleVersion
    compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

    compileOnly "com.android.tools.lint:lint-api:$lintVersion"
    compileOnly "com.android.tools.lint:lint-checks:$lintVersion"

    testImplementation 'junit:junit:4.13-beta-3'
    testImplementation "com.android.tools.lint:lint:$lintVersion"
    testImplementation "com.android.tools.lint:lint-tests:$lintVersion"
    testImplementation "com.android.tools:testutils:$lintVersion"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

jar{
    manifest{
        attributes 'Lint-Registry-V2': '[package name].ImportsIssueRegistry'
    }
}

我尝试了什么?

  • 检查 gradle 版本?我有最新版本 (3.4.2)
  • 尝试在 customlint 模块中将 Lint-Registry 更改为 Lint-Registry-V2
  • 还尝试将生成的 jar 添加到模块的 build.gradle 中:lintChecks fileTree(dir: 'libs', include: ['customlint.jar'] )

更新:

完整代码见here

请有人帮忙。

【问题讨论】:

  • 难道你不应该在这里给出你的包名:'[包名].ImportsIssueRegistry'
  • @rohithhammaiah 我已经给了它,请查看链接的仓库。
  • 你能解决你的问题吗?
  • @alphaguy nope.

标签: android android-lint


【解决方案1】:

我遇到了同样的问题,但这是由于 lint 规则的build.gradle 中的build.gradle 中缺少apply plugin: 'kotlin' 造成的,这不是您的问题。

但您可能想通过this video from ADS 了解最新版本的 API。谷歌真的应该更新他们的文档???

一些显着的差异:

  • 在资源文件中声明注册表
  • AGP 3.5.1

【讨论】:

    【解决方案2】:

    尝试使用lintPublish project(':customlint') 而不是lintChecks project(':customlint')。在撰写本文时,Google 的示例已过时。

    【讨论】:

    • 感谢您尝试提供帮助,但它不起作用。我更新了问题并包含了repo的链接,你可以看看
    【解决方案3】:

    我认为您可以删除任何 jar / Lint-Registry 东西

    看看这里: https://github.com/tikurahul/lint-experiments

    复制NoisyDetector 以帮助检查您的设置是否正确。

    【讨论】:

      猜你喜欢
      • 2021-03-17
      • 2014-12-23
      • 2013-05-20
      • 2019-09-25
      • 2017-01-14
      • 2014-03-28
      • 2014-10-30
      • 1970-01-01
      • 2018-09-14
      相关资源
      最近更新 更多