【问题标题】:> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/collections/ArrayStack.class> com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:org/apache/commons/collections/ArrayStack.class
【发布时间】:2016-04-07 19:12:21
【问题描述】:

在android studio上运行android应用时出现如下异常:

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/collections/ArrayStack.class

并发现 commons-beanutils-1.8.0.jarcommons-collections-3.2.1.jar 都包含相同的类(org/apache/commons /collections/ArrayStack.class) 位于项目的外部库中。

我不知道为什么这两个 jar 包含在这里和我的 build.gradle 如下:

`apply plugin: java

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8


tasks.withType(JavaCompile){
    options.encoding="UTF-8"
}

repositories {
    mavenCentral()
    jcenter()
    mavenLocal()
}

dependencies {

compile ('io.netty:netty-all:5.0.0.Alpha2')
compile ('org.springframework:spring-core:4.2.4.RELEASE')
compile ('org.springframework:spring-webmvc:4.2.4.RELEASE')
compile ('org.springframework:spring-jdbc:4.2.4.RELEASE')
compile ('org.springframework:spring-test:4.2.4.RELEASE')
compile ('org.springframework:spring-context:4.2.4.RELEASE')
compile ('org.springframework.data:spring-data-mongodb:1.8.2.RELEASE')
compile ('org.springframework.security:spring-security-core:4.0.3.RELEASE')
compile ('org.springframework.security:spring-security-web:4.0.3.RELEASE')
compile ('javax.servlet:javax.servlet-api:3.1.0')
compile ('org.mybatis:mybatis:3.3.0')
compile ('org.mybatis:mybatis-spring:1.2.3')
compile ('net.sf.json-lib:json-lib:2.4:jdk15')
compile ('c3p0:c3p0:0.9.1.2')
compile ('com.google.protobuf:protobuf-java:2.6.1')
compile ('mysql:mysql-connector-java:5.1.38')
compile ('org.mongodb:mongo-java-driver:3.2.0')
compile ('org.slf4j:slf4j-log4j12:1.7.2')
compile ('org.jasig.cas.client:cas-client-core:3.4.1')
compile ('commons-httpclient:commons-httpclient:3.1')
compile group: 'com.alibaba', name:'fastjson', version:'1.2.4'

testCompile ( 'junit:junit:4.12')
}`

如何解决此异常以及为什么下载并位于外部库中的 commons-beanutils-1.8.0.jarcommons-collection-3.2.1.jar ?提前感谢您的帮助。

【问题讨论】:

    标签: java android gradle


    【解决方案1】:

    没有你的工作区,很难说 commons-beanutils-1.8.0.jarcommons-collection-3.2.1.jar 的依赖关系,问题是因为您commons-beanutils-1.8.0.jar 已更新。 Commons BeanUtils描述详细信息。

    BeanUtils 的 1.7.x 和 1.8.x 版本已经分发了三个 jar:

    commons-beanutils.jar - 包含所有内容 commons-beanutils-core.jar - 不包括 Bean Collections 类 commons-beanutils-bean-collections.jar - 仅限 Bean Collections 类 主要的 commons-beanutils.jar 对 Commons Collections 有一个可选的依赖

    看到这种情况,我建议你更新使用commons-beanutils-1.9.0

    定位哪个库正在使用 commons-beanutils 和 commons-collections。您只需访问here 即可搜索您在项目中使用的所有依赖项。例如commons-httpclient:3.1,详细说明下可以找到编译依赖。

    希望对你有帮助。


    更新: 就像@EpicPandaForce 所说,使用gradle dependencies 是更简单的方法。感谢 EpicPandaForce。 我刚刚运行了与问题相同的依赖项,得到以下可以回答这个问题。

    +--- net.sf.json-lib:json-lib:2.4
    |    +--- commons-beanutils:commons-beanutils:1.8.0
    |    |    \--- commons-logging:commons-logging:1.1.1 -> 1.2
    |    +--- commons-collections:commons-collections:3.2.1
    |    +--- commons-lang:commons-lang:2.5
    |    +--- commons-logging:commons-logging:1.1.1 -> 1.2
    |    \--- net.sf.ezmorph:ezmorph:1.0.6
    |         \--- commons-lang:commons-lang:2.3 -> 2.5
    

    net.sf.json-lib 这就是这两个库的来源。

    【讨论】:

    • 我认为使用gradle dependenciesgradle :dependencies 来查找谁在使用commons-collections 是一个更好的解决方案。比手动在 maven 存储库中查看它。
    【解决方案2】:

    错误:

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

    Gradle 文件依赖:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile files ('jackson-annotations-2.2.2.jar')
        compile files ('jackson-core-2.2.2.jar')
        compile files ('jackson-databind-2.2.2.jar')
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile 'com.android.support:design:23.0.1'
        compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
        compile 'com.google.android.gms:play-services-maps:7.8.0'
        compile 'com.google.android.gms:play-services-location:7.8.0'
        compile 'com.github.orangegangsters:swipy:1.2.2@aar'
        compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
            transitive = true;
        }
        compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.2@aar') {
            transitive = true;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 2016-12-06
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多