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

I got exception as below when run the android application on android studio:

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

and find that commons-beanutils-1.8.0.jar and commons-collections-3.2.1.jar which both contained same class (org/apache/commons/collections/ArrayStack.class) located at External Libraries of project.

i don't know why these two jars included in here and my build.gradle as below:

`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')
}`

How to resolve this exception and why the commons-beanutils-1.8.0.jar and commons-collection-3.2.1.jar download and located at External Libraries? Appreciate your help in advance.

Answers


Without your workspace, it's not easy to say which dependency is related on commons-beanutils-1.8.0.jar and commons-collection-3.2.1.jar, the problem is cause you commons-beanutils-1.8.0.jar was updated. Commons BeanUtils describe the detail information.

The 1.7.x and 1.8.x releases of BeanUtils have distributed three jars:

commons-beanutils.jar - contains everything commons-beanutils-core.jar - excludes Bean Collections classes commons-beanutils-bean-collections.jar - only Bean Collections classes The main commons-beanutils.jar has an optional dependency on Commons Collections

As you see this situation, I recommend you to update to use commons-beanutils-1.9.0

To locate which library is using commons-beanutils & commons-collections. You can just visit here to search all dependencies which you used in your project. e.g. commons-httpclient:3.1, you can found compile dependencies under the detail description.

Hope this can help you.


Update: Like @EpicPandaForce said, use gradle dependencies is more easy way. Thanks to EpicPandaForce. I just ran the same dependencies like the question and got the following can answer this question.

+--- 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 That's where these 2 libraries came.


Error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/hamcrest/BaseDescription.class

Gradle file dependencies:

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;
    }
}

Need Your Help

alternate database schema queries in nhibernate

.net nhibernate ado.net

I am working on an asp.net business application and using nhibernate. My objective of using nhibernate is to minimize/avoid application porting effort on different databases(Oracle, SQL Server, Pos...