java.lang.RuntimeException:在模块 annotations-16.0.1.jar 和 annotations-java5-15.0.jar 中发现重复的类 org.intellij.lang.annotations.Flow

Khư*_*Mai 10 java intellij-idea

输出文本:

 Execution failed for task ':app:checkDebugDuplicateClasses'.
1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class org.intellij.lang.annotations.Flow found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.Identifier found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$AdjustableOrientation found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$BoxLayoutAxis found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$CalendarMonth found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$CursorType found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$FlowLayoutAlignment found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$FontStyle found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$HorizontalAlignment found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$InputEventMask found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$ListSelectionMode found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$PatternFlags found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$TabLayoutPolicy found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
  Duplicate class org.intellij.lang.annotations.JdkConstants$TabPlacement found in modules annotations-16.0.1.jar (org.jetbrains:annotations:16.0.1) and annotations-java5-15.0.jar (org.jetbrains:annotations-java5:15.0)
Run Code Online (Sandbox Code Playgroud)

Har*_*hra 51

这是两个罐子之间的冲突。您可以从 Modules_annotation 16.XXX 和 annotations-java5-XXXX jar 文件中找出您没有使用的那个。

我发现了两种方法来解决这个问题。

  1. 排除 JetBrains 注释模块是一种解决方法;为什么它首先出现在你的项目中?最有可能的是,当您真正想要的是 Android 自己的注释时,它会被 Android Studio 自动添加到您的类路径中。

因此,更好的解决方案是在 build.gradle 文件 [s] 中查找 org.jetbrains:annotations 依赖项,如下所示:

implementation 'org.jetbrains:annotations-java5:15.0'
Run Code Online (Sandbox Code Playgroud)

...并删除它。

如果 1 不起作用

  1. 请在您的模块级别 build.gradle 中添加以下行。
configurations {
            cleanedAnnotations
             compile.exclude group: 'org.jetbrains' , module:'annotations'
         }
Run Code Online (Sandbox Code Playgroud)

  • 哇...第二个有帮助...谢谢你拯救了我的一天! (2认同)
  • 根本不起作用。Android Studio 电鳗 | 2022.1.1 Build #AI-221.6008.13.2211.9477386,构建于2023年1月11日,运行时版本:11.0.15+0-b2043.56-8887301 amd64 VM:JetBrains sro的OpenJDK 64位服务器VM (2认同)

小智 39

我通过更改解决了我的问题

implementation 'androidx.room:room-compiler:2.4.0-beta01'
Run Code Online (Sandbox Code Playgroud)

annotationProcessor 'androidx.room:room-compiler:2.4.0-beta01'
Run Code Online (Sandbox Code Playgroud)


Ale*_*ort 27

Harsh Mishra 的答案是正确的,但是最新版本的 Android Studio 不再声明org.jetbrains:annotations-java5:15.0或在你的 gradle 依赖项中,并且编译org.jetbrains.kotlin:kotlin-stdlib:$version_kotlin的使用也被实现所取代,这样你的 build.gradle 应该如下所示:

    plugins {
        ...
    }

    android {
        ...
    }

    configurations {
        cleanedAnnotations
        implementation.exclude group: 'org.jetbrains' , module:'annotations'
    }

    dependencies {
        ...
    }
Run Code Online (Sandbox Code Playgroud)


Kev*_*lia 6

这是两个不同 lib/jar 文件中的单个工件之间的冲突。基本上,我们需要删除未使用的库或从任何一个库中删除工件。

从Kotlin 1.4开始,您不再需要以下依赖项

implementation "org.jetbrains.kotlin:kotlin-stdlib:$version_kotlin"
Run Code Online (Sandbox Code Playgroud)

所以删除这个依赖也可以解决这个问题。