Unable to merge dex

前端 未结 30 2659
深忆病人
深忆病人 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:54

    [ UNABLE TO MERGE DEX SOLVED ] After hours of stack overflowing I resolved the " UNABLE TO MERGE DEX ERROR "

    1. Update all the com.android.support lines in your gradle to v27.1.0

    Cause - Android has updated it support libraries to v27.1.0, so you have to change all the android support lines in your gradle file to 27.1.0 from 26.1.0

    1. Make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint. For example:

      allprojects { repositories { jcenter() maven { url "https://maven.google.com" } } }

    Cause :- Android cannot update the support libraries in the SDK manager and now it uses maven.google.com to update , so you have to include this to use 27.1.0 support libraries

    After Change Version: 1. Clean Project 2. Rebuild Project

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

    I had the same problem when I update from com.google.android.gms:play-services:11.2.2 to com.google.android.gms:play-services:11.4.0. This solved it for me:

    1. clean
    2. rebuild
    0 讨论(0)
  • 2020-11-21 22:56

    I tried every other solution, but no one worked for me. At the end, i solved it by using same dependency version by editing build.gradle. I think this problem occurres when adding a library into gradle which uses different dependency version of support or google libraries.

    Add following code to your build gradle file. Then clean and rebuild project.

    ps: that was old solution for me so you should use updated version of following libraries.

    configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.1.0'
            }
        } else if (requested.group == "com.google.android.gms") {
            details.useVersion '11.8.0'
            } else if (requested.group == "com.google.firebase") {
                details.useVersion '11.8.0'
              }
          }
    }
    
    0 讨论(0)
  • 2020-11-21 22:56

    For me it was updating the firebase messaging in app\build.gradle:

    compile 'com.google.firebase:firebase-messaging:10.0.1'
    

    to

    compile 'com.google.firebase:firebase-messaging:11.4.2'
    
    0 讨论(0)
  • 2020-11-21 22:58

    In case the top answers haven't worked for you, your issue may be that you have multiple dependencies that depend on the same library.

    Here are some debugging tips. In this sample code, com.google.code.findbugs:jsr305:3.0.0 is the offending library.

    Always clean and rebuild every time you modify to check your solution!

    1. Build with the --stacktrace flag on for more detail. It will complain about a class, Google that class to find the library. Here's how you can set up Android studio to always run gradle with the --stacktrace flag.

    2. Take a glance at the Gradle Console in Android Studio View > Tool Windows > Gradle Console after a build

    3. Check for repeated dependences by running ./gradlew -q app:dependencies. You can re-run this each time you modify the your build.gradle.

    4. In build.gradle,

      android {
              ...
              configurations.all {
                  resolutionStrategy {
                      // Force a particular version of the library 
                      // across all dependencies that have that dependency
                      force 'com.google.code.findbugs:jsr305:3.0.0'
                  }
              }
      }
      
    5. In build.gradle,

      dependencies {
          ...
          implementation('com.google.auth:google-auth-library-oauth2-http:0.6.0') {
              // Exclude the library for this particular import
              exclude group: 'com.google.code.findbugs'
          }
      }
      
    6. In build.gradle,

      android {
          ...
          configurations.all {
              resolutionStrategy {
                  // Completely exclude the library. Works for transitive
                  // dependencies.
                  exclude group: 'com.google.code.findbugs'
              }
          }
      }
      
    7. If some of your dependencies are in jar files, open up the jar files and see if there are any conflicting class names. If they are, you will probably have to re-build the jars with new class names or look into shading.

    Some more background reading:

    • Android - Understanding and dominating gradle dependencies
    • Gradle Documentation: Dependency Management for Java Projects
    • Gradle Documentation: ResolutionStrategy
    • StackOverflow: Error:Conflict with dependency 'com.google.code.findbugs:jsr305'
    • StackOverflow: How do I exclude all instances of a transitive dependency when using Gradle?
    • Google search StackOverflow for all related questions
    0 讨论(0)
  • 2020-11-21 23:00

    Pay attention to Warnings!

    Sometimes you only need to eliminate warnings and the error will be disappeared automatically. See below special case:


    I had these two dependencies in my module-level build.gradle file:

    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:recyclerview-v7:27.0.2'
    

    and Studio had warned (in addition to dex merging problem):

    All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.0.2, 21.0.3. Examples include com.android.support:animated-vector-drawable:27.0.2 and com.android.support:support-v4:21.0.3

    So I explicitly determined the version of com.android.support:support-v4 (see here for details) and both problems (the warning and the one related to dex merging) solved:

    implementation 'com.android.support:support-v4:27.0.2'  // Added this line (according to above warning message)
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:recyclerview-v7:27.0.2'
    

    See below comments for other similar situations.

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