添加依赖后无法合并dex

Unable to merge dex after adding dependencies

我收到错误:

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

添加以下两个依赖后:

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

这是我所有的依赖项:

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"
}

我的默认配置:

defaultConfig {

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

}

我升级了内存,添加了multiDexEnabled,添加了多dex的支持库。

有趣的是,我必须添加

exclude 'META-INF/DEPENDENCIES'

为了得到multidex错误。

我似乎找不到解决办法。

详细错误:

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

将此添加到您的应用程序中class..

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

赞 :-

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);

     }


}

编辑:- 由于您使用的是 targetSdkVersion <=23,因此您需要手动安装它。,. 并且不要忘记将 android:name="android.support.multidex.MultiDexApplication" 添加到 manifest.xml 中的应用程序标签中。像这样:-

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

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

您正在从 Gradle 未在其依赖项解析过程中排除的来源获取此 Java class 的两个副本。

一种可能是您的一个新依赖项对 Apache HttpCore 具有传递依赖性,但是 libs/droidText.0.2.jar 或您的其他依赖项之一具有其自己的 org.apache.http.annotation.NotThreadSafe.[=16= 副本]

Android Studio 具有项目树的 "External Libraries" 部分,如果您在项目视图中(而不是默认的 Android 视图):

据我所知,唯一的追踪方法是开始筛选您的图书馆,并尝试找出 2+ 具有 org.apache.http.annotation.NotThreadSafe 的图书馆。然后,试着弄清楚如何停止使用其中之一。具有此 class 的库可能是通过传递依赖项实现的,因此您还需要确定这些传递依赖项的来源。这将是痛苦的,这就是为什么我希望 newer versions of Android Studio will be more helpful here.