Dex error On Android Studio 3.0 Beta4
Asked Answered
B

15

53
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;
Bergren answered 5/9, 2017 at 11:30 Comment(9)
show build.gradleSchwarzwald
@IntelliJAmiya This is not a duplicate of the reported question. At least for me, the problem started with AS 3.0 beta 4 and I already use multidex.Amarillas
How? I don't have privileges, I thinkAmarillas
@Amarillas Yes . Thanks for mention . Its a bug ? sure ?Schwarzwald
I don't know yet for sure. But I can run ./gradlew assembleRelease on the command line without problems.Amarillas
@IntelliJAmiya still not sure if it's a bug but I posted an answer with the solution I found to the problem.Amarillas
Not working in Android Studio 3.0 RC2Procumbent
Try and add this to your gradle file: multiDexEnabled true It worked for me.Bis
Possible duplicate of Android MultiDex: an all time salvation is imperative (I know it is newer, but it is way better than this error-text-only post!)Superelevation
V
56

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

Velate answered 7/9, 2017 at 13:51 Comment(4)
I'm happy to help part of solution of your problemVelate
I wonder, why is the answer not usefull and why report the answer? @SagarTrehanVelate
This works on Android Studio 3.1 Canary. However it seems like i have to do this each time i make changes to gradle. Is there a lot term fix for this?Fricative
Worked for me using Android Studio 3.0Mobley
W
28

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'
        }
    }
}
Weirdie answered 30/10, 2017 at 20:54 Comment(3)
for me, this does not resolve the problem... I still continue working on resolve it..Joist
Try these steps: Delete your .gradle, clean and rebuild. Also don't forget add multiDexEnabled. Hope it helpsWeirdie
If you enable multidex and your minSDK is less than 5.0, then follow the instructions here: developer.android.com/studio/build/multidexToogood
A
19

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.
Amarillas answered 7/9, 2017 at 10:23 Comment(5)
Delete .gradle folder fixes my problem. Thanks for help!Bergren
Same issue on AS 3.0 Beta 7, unfortunately this is still not working for my case.Laager
Have tried all above solution but does not work for AS 3.0 beta 7. Kindly helpBozen
I still have the problem in AS 3.0.1Rabe
Invalidate caches and restart have broken all my Android Studio settings...Hinkle
P
9

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'
}
Pentlandite answered 25/10, 2017 at 13:34 Comment(2)
In my case 'com.android.volley' was being added twice somehow, I also added the exclude statement, now its working fine.Cloverleaf
running this script gave me could not determine java version from 9.0.1. I updated to Gradle from 4.1 to 4.2.1 using Android Studio 3.0Chatty
C
7

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>
Cookson answered 12/11, 2017 at 20:18 Comment(2)
If above code does not work then check your every library in the gradle by holding cursor on it, if it has available new version then Update it, sync, clean project, rebuild project and run. hopefully, it will work for you.Cookson
This code works for Android 5.1 and above... for below android version.. there is another way to add multidex support. developer.android.com/studio/build/multidex.htmlMagallanes
I
6

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.

Idolist answered 6/11, 2017 at 18:21 Comment(0)
G
4

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..

Gloriole answered 23/11, 2017 at 13:24 Comment(7)
what about a Linux User ? Same error I am getting. Please guide meDit
Do the same thing which I mentioned in your linux. i.e., Go to terminal the location of .gradle would be something like '~\.gradle\'Gloriole
I am trying but its not visible.. Which location you are trying to explain ? Where I installed my Android studio or project location ?Dit
No it is in your user home i.e., for ex: ~/.gradle/caches/..Gloriole
Thank you ... I solved it. There was mismatch version codeDit
Glad to helped youGloriole
Let us continue this discussion in chat.Gloriole
F
1

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.

Fireworm answered 28/10, 2017 at 13:47 Comment(1)
How did you get this conclusion? By trial and error?Lippe
L
1

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

Lunge answered 7/11, 2017 at 14:4 Comment(0)
R
0

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'
}
Reprint answered 1/11, 2017 at 20:28 Comment(0)
J
0

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.

Jannery answered 2/11, 2017 at 5:14 Comment(0)
G
0

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)

Greenish answered 13/11, 2017 at 10:33 Comment(0)
A
0

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

Anzac answered 9/12, 2017 at 21:35 Comment(0)
L
0

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

Loki answered 13/3, 2018 at 17:51 Comment(0)
M
-1

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
    }
}
Maleficent answered 24/2, 2018 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.