0
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/io/CopyUtils.class

It occurs this error.

The app builds success but when I get build apk, android studio show this message

This is my gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '25'
    defaultConfig {
        applicationId "com.example.thewell_dev.fourscompany"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.mobsandgeeks:android-saripaar:2.0.3'
    compile 'com.koushikdutta.ion:ion:2.1.9'
    compile 'gun0912.ted:tedpermission:1.0.2'
    compile 'com.android.support:design:22.+'
    compile 'com.estimote:sdk:0.13.0'
    compile 'jp.wasabeef:glide-transformations:2.0.0'
    compile 'com.afollestad:easyvideoplayer:0.3.0'
    compile 'com.github.jrvansuita:PickImage:v2.0.0'
    compile 'com.amazonaws:aws-android-sdk-s3:2.+'
    compile 'com.mindorks:placeholderview:0.6.0'
    compile 'com.tsengvn:Typekit:1.0.0'
    compile 'com.github.esafirm:RxDownloader:1.0.1'
    compile 'com.mlsdev.rximagepicker:library:1.1.2'
    compile 'io.reactivex:rxjava:1.0.14'
    compile 'com.kbeanie:image-chooser-library:1.5.2@aar'
    compile 'com.kbeanie:image-chooser-library:1.5.8'
    compile 'io.github.jeancsanchez.photoviewslider:photoviewslider:1.2.0'
    compile 'com.nononsenseapps:filepicker:3.1.0'
    compile 'com.gjiazhe:scrollparallaximageview:1.0'
    compile 'com.droidninja:filepicker:1.0.8'
    compile 'com.android.support:multidex:1.0.0'

}

I think external libraries have Commons-io-1.3.2.jar Commons-io-2.4.jar and both have CopyUtils.class

Anyway, It can't build apk and show that message.

Please anyone help me please

Polaris Nation
  • 1,085
  • 2
  • 18
  • 49
  • There are MANY questions like this on SO. Please search first. http://stackoverflow.com/questions/39957924/java-util-zip-zipexception-duplicate-entry/39958129#39958129 see the "EDIT" section here to run the command and exclude what is needed – ᴛʜᴇᴘᴀᴛᴇʟ Mar 25 '17 at 15:04
  • Possible duplicate of [Android Gradle compiling commons-io creates duplicate in library tree](http://stackoverflow.com/questions/35185512/android-gradle-compiling-commons-io-creates-duplicate-in-library-tree) – Techierj Mar 25 '17 at 15:10
  • @th3pat3l yes i think many question about it but i can't find the solution so I ask and in command line, i put ./gradlew app:dependencies not order in in or out message – Polaris Nation Mar 25 '17 at 15:29

3 Answers3

0

There is more than one dependency you have integrated which uses Apache Commons. just exclude them using following code in gradle.

compile('YOUR_DEPENDENCY') {
    exclude module: 'commons-io'
}
Techierj
  • 131
  • 9
  • Same issue happened two days ago with me. try this with all your dependency it will definitely work. – Techierj Mar 25 '17 at 15:25
  • 5 are you solved it? try like this? compile 'com.android.support:appcompat-v7:23.2.0'{ exclude module: 'commons-io'} compile 'com.android.support.constraint:constraint-layout:1.0.2'{ exclude module: 'commons-io' } testCompile 'junit:junit:4.12'{ exclude module: 'commons-io' } compile 'com.mobsandgeeks:android-saripaar:2.0.3'{ exclude module: 'commons-io' } ... like this? – Polaris Nation Mar 25 '17 at 15:31
  • yes **exclude module: 'commons-io'** helped me to resolved the issue. – Techierj Mar 25 '17 at 15:32
  • Just find Dependecy tree of your gradle and find where **common-io** is used and then it like this `compile ('com.mobsandgeeks:android-saripaar:2.0.3'){ exclude module: 'commons-io' }` – Techierj Mar 25 '17 at 15:41
  • to find project dependency given link will help you.. http://www.mkyong.com/gradle/gradle-display-project-dependency/ – Techierj Mar 25 '17 at 15:46
  • Thank you you saved my time – Polaris Nation Mar 26 '17 at 00:31
0

Found the solution for this issue . You need to exclude common-io from your app build.gradle .

android {
    configurations{
        all*.exclude module: 'commons-io'
    }
}
Sujit
  • 10,512
  • 9
  • 40
  • 45
0

Techierj answer is correct, but it will also exclude commons-io:2.4, and in my case I needed that. So you can exclude by specific group:

compile('YOUR_DEPENDENCY') {
    exclude group: 'org.apache.commons', module: 'commons-io'
}

This will only exclude version 1.3.2 from org.apache.commons, and will mantain commons.io:commons.io:2.4

Community
  • 1
  • 1
nelsito
  • 69
  • 1
  • 12