【问题标题】:java.util.zip.ZipException: duplicate entry: dagger/Provides.classjava.util.zip.ZipException:重复条目:dagger/Provides.class
【发布时间】:2023-04-05 08:01:01
【问题描述】:

当我同步项目时一切正常,但当我尝试运行时出现此错误:

错误:任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。 com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:dagger/Provides.class

这是我的应用 build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "appID"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    compile 'com.android.support:appcompat-v7:23.0.0'

    compile 'com.jakewharton:butterknife:8.4.0'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'

    apt 'com.google.dagger:dagger-compiler:2.5'
    compile 'com.google.dagger:dagger:2.5'
    provided 'javax.annotation:jsr250-api:1.0'

    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'

    compile('com.sumup:merchant-sdk:1.61.0@aar') {
        transitive = true
    }
}

如果我在没有compile 'com.google.dagger:dagger:2.5' 的情况下运行,则编译成功..请帮助。

【问题讨论】:

  • 感谢您分享自己问题的答案!您提到“问题可以关闭”,但我认为您的问题是有效的并且您的答案很有用,并且未来的读者可能有更多有用的信息可以贡献。请将您的答案从问题中编辑到self-answer,然后您可以正确接受以将问题标记为已完成。

标签: android sdk android-gradle-plugin dagger-2


【解决方案1】:

更新:

looks like sumup sdk 与 dagger 2.+ 不兼容。

所以我已经降级到 dagger 1.+ 并且工作正常。到目前为止没有出现其他问题。

【讨论】:

  • 感谢您解决这个问题。我评论了他们如何解决问题的错误,所以如果幸运的话,它不会长期成为问题。
【解决方案2】:

在降级之前,您是否考虑尝试将compile 'com.google.dagger:dagger:2.5' 替换为以下内容:

compile ('com.google.dagger:dagger:2.0') {
    exclude group: 'javax.inject'
}

这将排除重复的类。

【讨论】:

  • 你测试了吗?
  • 我在Espresso 中有一个重复的Provides 类有类似的问题,它不能很好地与 Dagger 2 配合使用。我上面引用的代码解决了我们项目中的问题,但你的里程可能会有所不同。
  • 来自他们的documentation,dagger 2 没有解决方法。我已经用你的版本对其进行了测试,但它不起作用。
【解决方案3】:

当我们切换到 Dagger 时,我遇到了类似的问题。

我们在 @Component 和 @Module 类的不同工件中使用相同的包名称,并且 Dagger 在我们使用相同包的每个工件中生成相同的 Dagger...Component.java 文件。

在我们将组件移动到每个工件中的唯一包中后,问题就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多