Unable to merge dex

前端 未结 30 2742
深忆病人
深忆病人 2020-11-21 22:14

I have Android Studio Beta. I created a new project with compile my old modules but when I tried launching the app it did not launch with the message:

Error:         


        
相关标签:
30条回答
  • 2020-11-21 22:46

    In my case, Unfortunately, neither Michel's nor Suragch's solutions worked for me.

    So I solved this issue by doing the following:

    In gradle:3.0 the compile configuration is now deprecated and should be replaced by implementation or api. For more information you can read here You can read the official docs at Gradle Build Tool

    The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.

    it's better to use implementation or api rather compile

    just replace compile with implementation, debugCompile with debugImplementation, testCompile with testImplementation and androidtestcompile with androidTestImplementation

    For example: Instead of this

    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.github.bumptech.glide:glide:4.0.0'
    

    use like this

    implementation 'com.android.support:appcompat-v7:26.0.2'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.github.bumptech.glide:glide:4.0.0'
    

    After that

    • Delete the .gradle folder inside your project ( Note that, in order to see .gradle, you need to switch to the "Project" view in the navigator on the top left )
    • Delete all the build folders and the gradle cache.
    • From the Build menu, press the Clean Project button.
    • After task completed, press the Rebuild Project button from the Build menu.

    Hope it will helps !

    0 讨论(0)
  • 2020-11-21 22:46

    Deleting .gradle as suggested by Suragch wasn't enough for me. Additionally, I had to perform a Build > Clean Project.

    Note that, in order to see .gradle, you need to switch to the "Project" view in the navigator on the top left:

    0 讨论(0)
  • 2020-11-21 22:46

    I find out the reason of this problem for my project. I was added one dependency twice in build.gradle. One time by adding dependency and one time again by adding jar dependency:

    compile 'org.achartengine:achartengine:1.2.0'
    ...
    implementation files('../achartengine-1.2.0.jar')

    after remove the first line problem solved.

    0 讨论(0)
  • 2020-11-21 22:47

    One of the possibilities is: the presence of the same library but with different versions in the dependencies.

    I had this problem with the following lines in gradle file:

    • compile fileTree(include: ['*.jar'], dir: 'libs')
    • compile 'com.google.code.gson:gson:2.8.2'

    The gson library was in my libs directory but with a previous version. I deleted the gson-2.3.1.jar from the libs directory and everything is back to normal.

    0 讨论(0)
  • 2020-11-21 22:48

    In my case it was gson-2.8.1.jar which I have added to libs folder of the project. But the reference was already there by SDK. So it was not necesary to add gson-2.8.1.jar to libs folder.

    When I took it out th gson-2.8.1.jar project compiles without this wiered error.

    So try to revise libs folder and dependencies.

    0 讨论(0)
  • 2020-11-21 22:48

    I encountered the same problem and found the real reason for my case. Previously, I also tried all the previous answers again, but it did not solve the problem. I have two module in my wear app project, and the build.gradle as follows:

    wear module's build.gradle:

    implementation project(':common')
    implementation files('libs/farmer-motion-1.0.jar')
    

    common module's build.gradle:

    implementation files('libs/farmer-motion-1.0.jar')
    

    Before upgrade to gradle 3.x, 'implementation' are all 'compile'.

    I run gradlew with --stacktrace option to get the stack trace, you can just click this on gradle console window when this problem arises. And found that dependency to the jar package repeated:

    Caused by: com.android.dex.DexException: Multiple dex files define Lcom/farmer/motion/common/data/pojo/SportSummary$2;
    

    Class SportSummary in the farmer-motion-1.0.jar package, after read the official migration guide, i changed my build.gradle to follows:

    wear module's build.gradle:

    implementation project(':common')
    // delete dependency implementation files('libs/farmer-motion-1.0.jar')
    

    common module的build.gradle:

    api files('libs/farmer-motion-1.0.jar') // change implementation to api
    

    Now wear module will has the dependency of farmer-motion-1.0.jar export by common module. If there has no dependency on jar package during runtime, 'implementation' dependency of jar package can also be change to 'compileOnly'.

    0 讨论(0)
提交回复
热议问题