Unable to merge dex after adding dependencies

大兔子大兔子 提交于 2019-12-09 03:56:47

问题


I am getting the error:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForPaidFreeDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

After adding the following two dependencies:

implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'
implementation 'com.prolificinteractive:material-calendarview:1.4.3'

Here are all of my dependencies:

dependencies {
compile 'com.android.support:multidex:1.0.2'
compile('com.github.florent37:materialviewpager:1.2.0@aar') {
    transitive = true
}
compile 'com.android.support:multidex:1.0.0'
compile files('libs/droidText.0.2.jar')
compile 'commons-io:commons-io:2.5'
compile 'com.google.code.findbugs:jsr305:3.0.0'
// in app billing
compile 'com.anjlab.android.iab.v3:library:1.0.44'
compile 'org.solovyev.android:checkout:1.2.1'
//
compile 'com.github.simbiose:Encryption:2.0.1'
compile 'com.android.support:support-v13:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'me.everything:providers-android:1.0.1'
//dateTime Picker
implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'
implementation 'com.prolificinteractive:material-calendarview:1.4.3'
//Date Time
compile 'net.danlew:android.joda:2.9.9'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.github.danysantiago:sendgrid-android:1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.google.firebase:firebase-ads:10.0.1'
//Logging
compile 'com.jakewharton.timber:timber:4.5.1'
//Retrofit
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.squareup.retrofit2:converter-scalars:2.3.0'
//Rx
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.0.8'

//butterknife
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

testCompile 'junit:junit:4.12'
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
testCompile 'org.robolectric:robolectric:3.1-rc1'
testCompile 'org.robolectric:shadows-support-v4:3.1-rc1'
testCompile 'org.glassfish:javax.annotation:10.0-b28'
testCompile 'org.mockito:mockito-core:2.0.7-beta'
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'org.robolectric:shadows-multidex:3.1-rc1'
testCompile 'org.assertj:assertj-core:1.7.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

My default config:

defaultConfig {

    applicationId "com.webnation.text2email"
    minSdkVersion 19
    targetSdkVersion 19
    multiDexEnabled true

}

I have upgraded the memory, added multiDexEnabled, added the support library for multi-dex.

Interesting, I had to add

exclude 'META-INF/DEPENDENCIES'

in order to get it to the multidex error.

I can't seem to find a solution.

Detailed error:

Error:07:48:24.286 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 07:48:24.286 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 07:48:24.286 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 07:48:24.286 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 07:48:24.286 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':app:transformClassesWithMultidexlistForPaidFreeDebug'. 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > java.io.IOException: Can't write [/Users/kristywelsh/Dropbox/SMS2Email1/app/build/intermediates/multi-dex/paidFree/debug/componentClasses.jar] (Can't read [/Users/kristywelsh/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.2/31fbbff1ddbf98f3aa7377c94d33b0447c646b6e/httpcore-4.3.2.jar(;;;;;;**.class)] (Duplicate zip entry [httpcore-4.3.2.jar:org/apache/http/annotation/NotThreadSafe.class])) 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try: 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 07:48:24.287 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 34s


回答1:


Duplicate zip entry [httpcore-4.3.2.jar:org/apache/http/annotation/NotThreadSafe.class]

You are picking up two copies of this Java class, from sources that Gradle is not netting out in its dependency resolution process.

One possibility is that one of your new dependencies has a transitive dependency on Apache HttpCore, but that libs/droidText.0.2.jar or one of your other dependencies has its own copy of org.apache.http.annotation.NotThreadSafe.

Android Studio has the "External Libraries" portion of the project tree, if you are in the Project view (rather than the default Android view):

The only way that I know of to track this down is to start sifting through your libraries and try to identify the 2+ that have org.apache.http.annotation.NotThreadSafe. Then, try to figure out how to stop using one of those. The libraries that have this class may be through transitive dependencies, and so you would also need to identify where those transitive dependencies came from. This will be painful, which is why that I am hoping that newer versions of Android Studio will be more helpful here.




回答2:


Add this to your application class..

   @Override
   protected void attachBaseContext(Context base) {
      super.attachBaseContext(LocaleHelper.onAttach(base, "hi"));
      MultiDex.install(this);
 }

like :-

also extend the MultiDexApplication by your Application class

public class MyApplication  extends MultiDexApplication {



      @Override
      protected void attachBaseContext(Context base) {
           super.attachBaseContext(base);
           MultiDex.install(this);
}


     @Override
     public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);

     }


}

Edit:- As you are using targetSdkVersion <=23 you need to install it manually.,. and dont forget to add android:name="android.support.multidex.MultiDexApplication" to your application tag in the manifest.xml.. like this :-

<application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>


来源:https://stackoverflow.com/questions/48990598/unable-to-merge-dex-after-adding-dependencies

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