Dex error On Android Studio 3.0 Beta4

AndroidAndroid Gradle-Pluginbuild.gradleDex

Android Problem Overview


Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/integration/android/IntentResult;

Android Solutions


Solution 1 - Android

I have same problem with Android Studio 3.0 beta 4. I found a solution.

1. From the Build menu, press the Clean Project button.

Clean Project

2. After task completed, press the Rebuild Project button from the Build menu.

enter image description here

Solution 2 - Android

For Android Studio 3.0 what I did was to add this to my gradle:

multiDexEnabled true

And it worked!

Example

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.xx.xxx"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 9
        versionName "1.0"
        multiDexEnabled true //Add this
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

Solution 3 - Android

So I solved this issue by doing the following:

  • Delete the ./gradle folder inside your project
  • Delete all the build folders and the gradle cache. I ran the following command:

How ?

 cd ~/[your project root folder] && find . -name build -exec rm -rf {} \; && rm -rf $HOME/.gradle/caches/

Assuming your gradle config files are in the $HOME/.gradle folder.

  • Inside Android Studio, went to File > Invalidate caches / Restart... and invalidated the caches and restarted it.

Solution 4 - Android

You should be able to get to the cause of this error by inspecting your dependencies with gradle and looking for duplicates like this: ./gradlew -q app:dependencies

In my case, the following error was happening at build time:

Duplicate zip entry [httpcore-4.4.1.jar

and it was resolved by doing this in my build.gradle:

implementation ('me.dlkanth:stetho-volley:1.0') {
    exclude group: 'org.apache.httpcomponents'
}

Solution 5 - Android

If your minSdkVersion is 21 or higher

   android {
        defaultConfig {
           multiDexEnabled true
        }
    }

if your minSdkVersion is 20 or lower

1) you must add the following library in dependencies

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

2) Create a java class then extend it from Application and override attachBaseContext method.

 public class MyApplication extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

3) Mention the created class inside manifest in application tag.

    <application
        android:name=".MyApplication"
.
.
.
    </application>

Solution 6 - Android

Check your dependencies for latest version usually it is inconsistency with the version of any of your dependencies.

1.Build > Clean Project 2. Rebuild your project

Check the verbose log for the dependency causing the merge issue and update the same. Repeat the same for each dependencies.

Solution 7 - Android

I faced same issue in Android Studio 3.0.1, I tried all possible cases nothing worked for me as mentioned above, finally I solved it by

Solution1:

  • Close Android Studio
  • Delete .gradle folder located at C:\Users\YourComputerName\.gradle not from app's .gradle
  • Restart android studio

It will download all the necessary jars and add to your build path

Solution2:

  • Delete duplicate jar from libs folder in app/libs
  • Rerun the app again

Because if there is duplicate jar file which already defined in build.gradle file it causes issue.

This solved the issue for me. It may help others..

Solution 8 - Android

This error can have multiple reasons. No clean and rebuild or anythging like that did the job for me.

For me the problem was the dependency:

compile 'org.jetbrains:annotations-java5:15.0'

I removed it and everything worked fine.

Solution 9 - Android

Change "compile" to "compileOnly" this is what worked for me.

Solution 10 - Android

In my case the culprit was SendGrid lib, added this and it got fixed:

compile 'com.github.danysantiago:sendgrid-android:1',{
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}

Solution 11 - Android

I am using Studio 3.0.0 release. In my case there was the only solution: I have removed old JARs from the "libs" folder in my project: it was "ksoap2" package with dependencies. Packages obtained with gradle usually do not conflict with each other, at least if you are using the most popular ones. But an old JAR in libs folder may crush your build if it includes all own dependencies.

Solution 12 - Android

I have tried other comments from removing gradle and bla bla bla, but adding multiDexEnabled true solving my problem, I investigate that my apk has reached Over 64K Method.

enter image description here

> Ref: https://developer.android.com/studio/build/multidex.html)

Solution 13 - Android

I am using Android Studio 3.0.1 Build #AI-171.4443003, built on November 9, 2017

I delete jar file from libs folder. And that work fine for me

Solution 14 - Android

I am using Android Studio 3.0.1 and was facing the same problem. If others answer doesn't works try this:

Tools -> Android -> Sync Project with Gradle Files

It worked for me Sync Project with Gradle Files

Solution 15 - Android

Sometime it can happens due to same library (jar file) present two times or your project has reached 64k methods limit.

Solution:

  1. Remove Databinding if your project use this

  2. Remove same type library from lib folder or, delete .gradle file from c//user//your_pc//.gradle

  3. apply this in your build.gradle

    android { defaultConfig { multiDexEnabled true } }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnkita-user3449434View Question on Stackoverflow
Solution 1 - AndroidY.E.S.View Answer on Stackoverflow
Solution 2 - AndroidProdigyView Answer on Stackoverflow
Solution 3 - AndroidADevView Answer on Stackoverflow
Solution 4 - AndroidIgorGanapolskyView Answer on Stackoverflow
Solution 5 - AndroidShahzad AfridiView Answer on Stackoverflow
Solution 6 - AndroidWillsView Answer on Stackoverflow
Solution 7 - AndroidShailendra MaddaView Answer on Stackoverflow
Solution 8 - AndroidPalmView Answer on Stackoverflow
Solution 9 - AndroidPieter van der MullenView Answer on Stackoverflow
Solution 10 - AndroidZoharView Answer on Stackoverflow
Solution 11 - AndroidAlmazView Answer on Stackoverflow
Solution 12 - AndroidPutra Christianto PurbaView Answer on Stackoverflow
Solution 13 - AndroidIceCreamVanView Answer on Stackoverflow
Solution 14 - AndroidjgodinezView Answer on Stackoverflow
Solution 15 - AndroidShaonView Answer on Stackoverflow