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

Android构建注解依赖冲突咨询:org.intellij与org.jetbrains版本冲突

解决Duplicate class org.intellij.lang.annotations.Identifier错误

第一步:修正Gradle配置中的错误依赖

你的模块级Gradle里存在两处错误依赖配置,先进行修正:

  • 移除implementation("com.google.dagger:hilt-android-gradle-plugin:2.51")——Gradle插件不能作为implementation依赖引入,插件已在plugins块中配置。
  • 将implementation("androidx.hilt:hilt-compiler:1.2.0")改为kapt("androidx.hilt:hilt-compiler:1.2.0")(使用kapt时)或ksp("androidx.hilt:hilt-compiler:1.2.0")(使用ksp时)——注解处理器必须通过kapt/ksp声明,不能用implementation。

第二步:解决重复类问题

方案A:强制统一注解版本

在模块级Gradle的dependencies块上方添加配置,强制所有依赖使用你指定的org.jetbrains:annotations:23.0.0版本,自动覆盖老版本的com.intellij:annotations:12.0:

configurations.all {
    resolutionStrategy.force("org.jetbrains:annotations:23.0.0")
}

方案B:排除间接依赖中的老版本注解

  1. 定位老版本注解来源:在Android Studio终端执行命令查看依赖树
    • Mac/Linux:./gradlew app:dependencies
    • Windows:gradlew.bat app:dependencies
  2. 在输出中搜索com.intellij:annotations:12.0,找到它所属的父依赖(比如可能来自Hilt或Navigation库)
  3. 在该父依赖的声明中添加排除规则,例如假设老版本注解来自hilt-android:
implementation("com.google.dagger:hilt-android:2.51") {
    exclude(group = "com.intellij", module = "annotations")
}

第三步:同步并重新构建

修改完成后,点击Android Studio右上角的「Sync Project with Gradle Files」,再执行「Build > Rebuild Project」。

另外,你的模块plugins块可简化为如下形式(若使用ksp需保证版本与Kotlin 1.9.22匹配):

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("kotlin-kapt")
    // id("com.google.devtools.ksp") version "1.9.22-1.0.17" // 启用时需保证版本匹配
    id("com.google.dagger.hilt.android") version "2.51"
    id("kotlin-parcelize")
}

内容的提问来源于stack exchange,提问作者Ned General

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 00:10:37