java.lang.RuntimeException:在模块annotations-16.0.1.jar和annotations-java5-15.0.jar中找到重复的类org. intellij. lang.注解.流

xienkqul  于 2023-01-01  发布在  Java
关注(0)|答案(4)|浏览(679)

输出文本:

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)
bxjv4tth

bxjv4tth1#

这是两个jar之间的冲突,您可以从Modules_annotation 16.XXX和annotations-java 5-XXXX jar文件中找出您没有使用的jar。
我找到了两个解决办法。
1.排除JetBrains注解模块是一种变通方案;为什么它会出现在您的项目中?最有可能的情况是,当您真正需要的是Android自己的注解时,它被Android Studio自动添加到了您的类路径中。
因此,更好的解决方案是在您的build.gradle文件中查找org.jetbrains:annotations依赖项,如下所示:

implementation 'org.jetbrains:annotations-java5:15.0'

......并将其移除。
如果1不工作
1.请在模块级build. gradle中添加以下行。

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

r1wp621o2#

Harsh Mishra's答案是正确的,但是最新版本的Android Studio不再在您的gradle依赖项中声明org.jetbrains:annotations-java5:15.0org.jetbrains.kotlin:kotlin-stdlib:$version_kotlin,并且compile的使用也被implementation所取代,因此您的build.gradle应如下所示:

plugins {
        ...
    }

    android {
        ...
    }

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

    dependencies {
        ...
    }
hgc7kmma

hgc7kmma3#

我通过更改

implementation 'androidx.room:room-compiler:2.4.0-beta01'

annotationProcessor 'androidx.room:room-compiler:2.4.0-beta01'
fjnneemd

fjnneemd4#

这是两个不同的lib/jar文件中的单个工件之间的冲突。基本上我们需要删除未使用的lib或从任何一个lib中删除工件。
从Kotlin1.4开始,您不再需要以下依赖项

implementation "org.jetbrains.kotlin:kotlin-stdlib:$version_kotlin"

因此,删除此依赖项也将解决此问题。

相关问题