0

I am getting the following error when I try to build my project. This error occurs when I was trying to add JavaMail api in my project.

     Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

This is my gradle file:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.persi.eatery"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    packagingOptions {

        exclude 'META-INF/mailcap.default'
        exclude 'META-INF/mimetypes.default'
    }
    defaultConfig {
        multiDexEnabled true
    }        
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.sun.mail:android-mail:1.6.1'
    implementation 'com.sun.mail:android-activation:1.6.1'
    implementation project(':library')

}

apply plugin: 'com.google.gms.google-services'

My library gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

Project gradle file

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

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.java.net/content/groups/public/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

P.S I have already tried Clean project followed by rebuild project as suggested in other answers but its still not working.Thanks in advance Unable to merge dex

Saif
  • 723
  • 6
  • 21
Paras Gupta
  • 63
  • 1
  • 7

1 Answers1

0

You have a dependencies conflict. Try to see your dependencies via command ./gradlew app:dependencies (Details here ). And you will see the next situation:

android-mail and android-activation

As you can see android-mail depends on android-activation. I think you don't need to use the line implementation 'com.sun.mail:android-activation:1.6.1'

P.S. For debugging builds you can use the next flag "--stacktrace". Then you can see more information about your issue.

mikhail-t
  • 4,103
  • 7
  • 36
  • 56
Den
  • 23
  • 5
  • Updated your post. To make your images show please use "Add Image" (Ctrl + G) button in the answer editor, it will insert correct markdown code. – mikhail-t Mar 07 '18 at 15:27
  • 1
    @mik-t Thanks. I have too little reputation to do that. I can add only a link. – Den Mar 07 '18 at 16:03
  • oh! I didn't realize that you need certain reputation for full images, good to know. – mikhail-t Mar 07 '18 at 21:11