构建项目时Dex错误

时间:2018-02-19 11:15:42

标签: android android-gradle build.gradle dex

当我尝试构建项目时出现以下错误。当我尝试在项目中添加JavaMail api时会发生此错误。

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

这是我的gradle文件:

    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'

我的图书馆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'
        }
    }

}

项目gradle文件

// 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我已经尝试过Clean项目,然后按照其他答案的建议重建项目,但它仍然无效。谢谢提前 Unable to merge dex

1 个答案:

答案 0 :(得分:0)

您有依赖项冲突。尝试通过命令./gradlew app:dependencies(详细信息here)查看您的依赖项。你会看到下一个情况:

android-mail and android-activation

正如您所看到的,android-mail取决于android-activation。我认为您不需要使用行implementation 'com.sun.mail:android-activation:1.6.1'

P.S。对于调试版本,您可以使用下一个标志“--stacktrace”。然后,您可以查看有关您的问题的更多信息。