Dex error On Android Studio 3.0 Beta4

Solution 1:

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:

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:

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:

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