修复Gradle中的依赖项解决错误

时间:2019-09-19 14:19:45

标签: android gradle android-gradle-plugin

当我将okhttp3依赖关系从3.4.1更新到4.1.0时,我的项目无法构建,并引发以下错误。

awk '
FNR==NR{
  len=length($0)>len?length($0):len
  next
}
{
  printf("%s%"len-length($0)+1"s%s\n",$0,OFS,"abcd")
}
'  Input_file  Input_file

存在重复依赖项的问题(annotations-12.0.jar和annotations-13.0.jar),并且抄袭了我的Gradle文件。

Duplicate class org.intellij.lang.annotations.Identifier found in modules annotations-12.0.jar     
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants found in modules annotations-12.0.jar     
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$AdjustableOrientation found in modules 
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar       
(org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$BoxLayoutAxis found in modules annotations-                              
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$CalendarMonth found in modules annotations- 
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$CursorType found in modules annotations-   
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$FlowLayoutAlignment found in modules        
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$FontStyle found in modules annotations-  
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$HorizontalAlignment found in modules   
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar 
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$InputEventMask found in modules   
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$ListSelectionMode found in modules  
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$PatternFlags found in modules annotations-
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TabLayoutPolicy found in modules 
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TabPlacement found in modules annotations-        
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderJustification found in modules 
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar 
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderTitlePosition found in modules    
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$TreeSelectionMode found in modules   
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.Language found in modules annotations-12.0.jar 
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.MagicConstant found in modules annotations-12.0.jar 
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.Pattern found in modules annotations-12.0.jar 
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.PrintFormat found in modules annotations-12.0.jar       
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.PrintFormatPattern found in modules annotations-12.0.jar  
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

   Duplicate class org.intellij.lang.annotations.RegExp found in modules annotations-12.0.jar     
   (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

   Duplicate class org.intellij.lang.annotations.Subst found in modules annotations-12.0.jar  
   (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

    Duplicate class org.jetbrains.annotations.Nls found in modules annotations-12.0.jar  
    (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

     Duplicate class org.jetbrains.annotations.NonNls found in modules annotations-12.0.jar 
     (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
     Duplicate class org.jetbrains.annotations.NotNull found in modules annotations-12.0.jar \
    (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
    Duplicate class org.jetbrains.annotations.Nullable found in modules annotations-12.0.jar 
    (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
    Duplicate class org.jetbrains.annotations.PropertyKey found in modules annotations-12.0.jar   
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.jetbrains.annotations.TestOnly found in modules annotations-12.0.jar                  
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

    Go to the documentation to learn how to Fix dependency resolution errors.

我无法解决此错误,我试图显式提及注释依赖项,但是它不能解决我的问题,这是我查看的medium article

4 个答案:

答案 0 :(得分:3)

您的gradle中有implementation 'androidx.cardview:cardview:1.0.0'中的2。
删除其中之一,然后重新同步。

更新

也删除implementation 'com.intellij:annotations:+@jar'

答案 1 :(得分:1)

对于另一个人,也许谁会到达这里。如果您使用冲突传递依赖项的模块,也会发生这种情况。

错误消息的代码段:“在模块jetified-javaee-web-api-7.0.jar(javax:javaee-web-api:7.0)和jetified-tyrus-standalone-模块中找到重复的类javax.websocket.server.ServerEndpointConfig client-1.14.jar(org.glassfish.tyrus.bundles:tyrus-standalone-client:1.14)“

就我而言,我正在使用Tyrus Websocket。在“ libs”文件夹中使用我的另一个库时,一切都很好。将该库转换为模块后,在同一项目中,我开始收到该错误。

这是因为我的lib在主App上利用了“ javax:javaee-web-api:7.0”,该软件包具有Tyrus中已经存在的软件包。由于lib模块将继续需要该类,因此我只设置了“ compileOnly”而不是“ implementation”,然后阳光再次照耀。我认为以root的'build.gradle'身份同时加入两者也是可行的。

答案 2 :(得分:0)

build.gradle

implementation 'com.intellij:annotations:12.0@jar'

gradle.properties

android.enableJetifier=true

答案 3 :(得分:0)

在 gradle.properies 中使用这一行

android.enableJetifier=true

gradle.properies