You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android自定义lint单元测试报错NoSuchFieldError: USE_PSI_CLASS_FILES_READING

自定义Lint规则单元测试USE_PSI_CLASS_FILES_READING报错解决方案

该报错本质是项目中Lint相关依赖与Kotlin编译器依赖版本不匹配导致,USE_PSI_CLASS_FILES_READING是高版本Kotlin编译器插件新增的配置字段,低版本依赖中不存在该字段,因此会抛出字段找不到的运行时错误。

可按以下步骤排查修复:

  • 统一所有Lint相关依赖版本,确保com.android.tools.lint:lint-api、com.android.tools.lint:lint-tests的版本和项目使用的AGP版本完全对齐,禁止出现不同Lint依赖使用不同版本的情况。
  • 排除lint-tests传递引入的冲突依赖,lint-tests默认会携带指定版本的Kotlin编译器依赖,和项目全局Kotlin版本不一致时就会触发类冲突,可在依赖声明中手动排除冲突包后显式引入匹配版本:
dependencies {
    compileOnly "com.android.tools.lint:lint-api:你的AGP版本号"
    testImplementation("com.android.tools.lint:lint-tests:你的AGP版本号") {
        exclude group: 'org.jetbrains.kotlin', module: 'kotlin-compiler-embeddable'
    }
    // 替换为你项目全局使用的Kotlin版本号
    testImplementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:你的Kotlin版本号"
}
  • 强制指定测试类路径的依赖版本,在lint规则模块的build.gradle中添加分辨率策略,避免Gradle自动选择高版本依赖:
configurations.testImplementation {
    // 替换为对应版本号
    resolutionStrategy.force 'org.jetbrains.kotlin:kotlin-compiler-embeddable:你的Kotlin版本号'
    resolutionStrategy.force 'com.android.tools.lint:lint-api:你的AGP版本号'
}
  • 临时兼容方案:如果暂时无法对齐版本,可将所有Lint相关依赖降级到7.2.x版本,该版本区间未引入对应字段变更,不会触发该报错。

内容的提问来源于stack exchange,提问作者Luis Talavera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 05:36:01