Unable to merge dex

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

提交回复
热议问题