Unable to merge dex

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

提交回复
热议问题