Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 5

This is my gradle file:

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'

repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 27
defaultConfig {
    vectorDrawables.useSupportLibrary = true
    applicationId "com.android.****"
    minSdkVersion 16
    targetSdkVersion 27
    buildToolsVersion '28.0.0-rc1'
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner         "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    targetCompatibility JavaVersion.VERSION_1_8
    sourceCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
    pickFirst 'META-INF/license.txt'
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/rxjava.properties'
    exclude 'org/apache/*' // for duplicate use in chatKit
    exclude 'org/apache/http/version.properties'
    exclude 'org/apache/http/client/version.properties'
    exclude 'org/apache/http/entity/mime/version.properties'
}

afterEvaluate {
    tasks.matching {
        it.name.startsWith('dex')
    }.each { dx ->
        if (dx.additionalParameters == null) {
            dx.additionalParameters = ['--multi-dex']
        } else {
            dx.additionalParameters += '--multi-dex'
        }
    }
}
dexOptions {
    preDexLibraries = false
    javaMaxHeapSize "2g" // 2g should be also OK
}
}
ext {
supportVersion = '25.3.1'
picassoVersion = '2.5.2'
circleImageViewVersion = '2.1.0'
shapeImageViewVersion = '0.9.3'
circleindicatorVersion = '1.2.2@aar'
}
dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')

//noinspection GradleDynamicVersion
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:design:27.0.2'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.android.support:multidex:1.0.2'
// MaterialTextField
implementation 'com.github.florent37:materialtextfield:1.0.7'

// Network monitoring
implementation 'com.novoda:merlin:1.1.6'

// Volley http library
implementation 'com.android.volley:volley:1.0.0'

// Pretty Toast
implementation 'ua.com.crosp.solutions.library:pretty-toast:0.2.0'

// PageIndicatorView
implementation 'com.romandanylyk:pageindicatorview:1.0.0'

// Material About
implementation 'com.github.jrvansuita:MaterialAbout:0.2.0'

// rebound
implementation 'com.facebook.rebound:rebound:0.3.8'

// CircleImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'

// Customizable Timeline View for Android
implementation 'com.github.qapqap:TimelineView:v1.6'

// Android Chart
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

// ChatKit for Android

// implementation 'com.github.stfalcon:chatkit:0.2.2'
implementation "com.github.siyamed:android-shape-imageview:$shapeImageViewVersion"

// Utils
implementation "me.relex:circleindicator:$circleindicatorVersion"

// Picasso
implementation 'com.squareup.picasso:picasso:2.71828'

// Android View Animations
implementation 'com.daimajia.easing:library:2.0@aar'
implementation 'com.daimajia.androidanimations:library:2.3@aar'

// Java WebSockets
implementation('io.socket:socket.io-client:0.8.3') {
    exclude group: 'org.json', module: 'json'
}

// Android library project for cropping images
implementation 'com.soundcloud.android:android-crop:1.0.1@aar'
implementation('com.crashlytics.sdk.android:answers:1.4.1@aar') {
    transitive = true;
}
implementation project(':chatkit')

}

Top-level build file:

       // Top-level build file where you can add configuration options common to all sub-projects/modules.

   buildscript {

       repositories {
           google()
           jcenter()
           maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
           maven { url 'https://maven.fabric.io/public' }

       }
       dependencies {
           classpath 'com.android.tools.build:gradle:3.2.0-alpha01'
           // classpath 'com.android.tools.build:gradle:2.14.1'
           classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT'
           classpath 'com.novoda:bintray-release:0.8.0' // for chatKit library
       }
   }

   allprojects {

       repositories {
           google()
           jcenter()
           maven { url "https://jitpack.io" }
           flatDir {
               dirs 'libs'
               dirs project(':app').file('libs')
           }

       }

   }
   task clean(type: Delete) {
       delete rootProject.buildDir
   }

The ocmplete error I get when compiling the project is:

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

The complete error is as follows:

    * Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: Error while generating the main dex list.
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 29 more
    Caused by: com.android.build.api.transform.TransformException: Error while generating the main dex list.
    at com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:127)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 41 more
    Caused by: com.android.builder.multidex.D8MainDexList$MainDexListException: com.android.tools.r8.errors.CompilationError: Program type already present: org.apache.http.impl.cookie.BestMatchSpec
    at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:87)
    at com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:114)
    ... 44 more
    Caused by: com.android.tools.r8.errors.CompilationError: Program type already present: org.apache.http.impl.cookie.BestMatchSpec
    at com.android.tools.r8.utils.ProgramClassCollection.resolveClassConflictImpl(ProgramClassCollection.java:64)
    at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:25)
    at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:24)
    at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:121)
    at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:122)
    at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:86)
    at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:36)
    at com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:95)
    at com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:83)
    ... 45 more

Edit 2:

public class App extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
 .
 ..
 ...
 ....
like image 972
Iman Marashi Avatar asked Apr 13 '18 10:04

Iman Marashi


2 Answers

I was having the same problem. One thing you can try is Clean Project and then Rebuild Project. It worked for me.

like image 77
Ikco 2420 Avatar answered Nov 10 '22 18:11

Ikco 2420


Try clean android studio cache from File > Invalidate Caches / Restart. it worked for me

like image 35
Anice Jahanjoo Avatar answered Nov 10 '22 19:11

Anice Jahanjoo