5

I am developing one project. This is working fine with Android studio 2.3.3, but what happen is when i updated my Android Studio 3.0 and open my project then it can't assembled and it send me below error Log.

Error Log

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/io/IOCase;
Error:com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/io/IOCase;
Error:    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error:  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error:  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error:  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error:  at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error:  at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error:  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error:  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error:  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error:  at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/io/IOCase;

Please don't make it duplicate because i have tried below all the things

  • Clean project
  • Rebuild project
  • Deleted /.gradle folder in project after Reopen project and clean and rebuild
  • Deleted .gradle cash folder after Reopen project and clean and rebuild

Other think is i checked below stack overflow questions and its answer and other also then also i don't get the solution.

1. Question, 2. Question, 3. Question, 4. Question and 5. Question

Project level build.gradle file

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:3.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app level build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.mypackage"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        // for render script to create blur image
        renderscriptTargetApi 18
        renderscriptSupportModeEnabled true

        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    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:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:multidex:1.0.0'
    testCompile 'junit:junit:4.12'

    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    //google API
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'com.google.android.gms:play-services-places:10.0.1'
    compile 'com.google.android.gms:play-services-maps:10.0.1'

    //facebook SDK
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'

    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
    compile ('org.apache.commons:commons-lang3:3.4'){
        exclude module: 'commons-io'
    }

    compile('net.yazeed44.imagepicker:imagepicker:1.3.0') {
        exclude module: 'cam2'
    }
}
apply plugin: 'com.google.gms.google-services'

Please do some help that how i can fix this issue. May i know if you need any thing from my side. Help would be very appreciate. Thank in advance.

Ninja
  • 678
  • 10
  • 26
  • 1
    Do you have any JARs in `libs/`? If not, delete `compile fileTree(dir: 'libs', include: ['*.jar'])`, as you are not using that line. If you are, then what JARs do you have in there. Somewhere, you have 2+ dependencies that define `org.apache.commons.io.IOCase`, and you need to fix the duplication. – CommonsWare Oct 30 '17 at 12:32
  • I don't used any `jar` file but when i create the project then its automatically added that line. Can remove that line and rebuild again ? I tried with `exclude module` also but then also not working? – Ninja Oct 30 '17 at 12:36
  • You can (and should) remove the line, but that will not clear up the problem. 2+ of your other dependencies must include that class. One probably is `org.apache.commons:commons-lang3:3.4`. You would need to find which other one has it, then stop using one of those dependencies. I am fairly certain that none of the `com.android.support` libraries define `org.apache.commons.io.IOCase`, so I recommend that you start by examining the other dependencies. – CommonsWare Oct 30 '17 at 12:39
  • Dependencies looks like this https://gist.github.com/anonymous/78aef3725caad6cab6bd8bb7abdbf558 but i don't know how to find ? – Ninja Oct 30 '17 at 12:42
  • Well, the class is `org.apache.commons.io.IOCase`. You have both `org.apache.commons:commons-io:1.3.2@jar` and `commons-io:commons-io:1.3.2@jar` in that list. My guess is that your problem lies there. Use an `exclude` to get rid of one of those, and see if your problem clears up. – CommonsWare Oct 30 '17 at 13:04
  • I have tried as i updated in my question gradle file but not working. – Ninja Oct 30 '17 at 13:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157806/discussion-between-ninja-and-commonsware). – Ninja Oct 30 '17 at 13:25
  • I get the same type of error when I try and install the app on 4.4.4. It is referencing a third party file by one of my own modules. When I install the app on 6.0.1 the error does not happen. So the cause must be a different reason. – Brian Reinhold Jan 15 '18 at 22:35
  • @BrianReinhold as the given answer and comments that whenever this kind of error will occur then we have to find that in which lib conflict our another library, but if there are so many libraries and not easy to identify then you can fix it like this – Ninja Jan 16 '18 at 08:33

2 Answers2

23

I agree with @CommonsWare that there is one another lib also contain commons-io in your project.

There is an option to fix this conflict issue in gradle dependency. Add below code in your app level build.gralde file.

configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute module('org.apache.commons:commons-io:1.3.2') with module('commons-io:commons-io:1.3.2')
    }
}

Reason is that why that 'org.apache.commons:commons-io:1.3.2' is conflict Check this stack overflow question's answer.

Note:- To know more about apache commons collections and its different versions check this answer

Farmer
  • 4,093
  • 3
  • 23
  • 47
3

If you're explicitly including this dependency in your build.gradle file:

org.apache.commons:commons-io:1.3.2

replace it with this one (or a later version):

commons-io:commons-io:2.4

You may need to do a clean/rebuild to get rid of a cached version. The org.apache... named one is both misnamed and now very out-of-date. Weirdly, some other org.apache... named ones are apparently OK.

scottt
  • 8,301
  • 1
  • 31
  • 41