Dex error On Android Studio 3.0 Beta4

99封情书 提交于 2019-11-26 16:35:36

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.

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

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

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

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

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>

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.

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

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.

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

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

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.

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.

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

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

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

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
    }
}
Alexey Taran

Solved this by removing the Android Data Binding library:

dataBinding {
    enabled = true
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!