Android错误:无法合并dex

时间:2018-05-29 14:50:17

标签: android merge android-gradle

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

我收到以下错误

这是我的构建gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.ryan.mychatapp"
        minSdkVersion 21
        targetSdkVersion 26
        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'
        }
    }
}

dependencies {
    //noinspection GradleCompatible
    implementation 'com.google.firebase:firebase-storage:11.2.0'
    //noinspection GradleCompatible
    compile 'com.google.android.gms:play-services:11.2.0'
    compile 'com.android.support:support-v4:26.1.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.google.firebase:firebase-database:11.2.0'

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:11.2.0'
    compile 'com.google.firebase:firebase-database:11.2.0'
    compile 'com.google.firebase:firebase-messaging:11.2.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    testImplementation 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    implementation 'com.firebaseui:firebase-ui-database:2.1.1'
    compile 'id.zelory:compressor:2.1.0'
}

这是我的另一个构建gradle

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

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

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

我已经添加了multiDexEnabled,但错误会不断出现。我已经尝试过,清理并重建,但没有一个工作,我该怎么办?我不确定我的gradle有什么问题?我在这篇文章中粘贴了我的全部笔记。

让我知道我应该改变哪一部分

1 个答案:

答案 0 :(得分:1)

您正在混合实现和编译,只使用所有依赖项的实现,因为已弃用编译。还要更新您的gradle插件。

dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
    }


dependencies {
    //noinspection GradleCompatible
    implementation 'com.google.firebase:firebase-storage:11.2.0'
    //noinspection GradleCompatible
    implementation 'com.google.android.gms:play-services:11.2.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.firebase:firebase-database:11.2.0'

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-auth:11.2.0'
    implementation 'com.google.firebase:firebase-database:11.2.0'
    implementation 'com.google.firebase:firebase-messaging:11.2.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:multidex:1.0.1'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    implementation 'com.squareup.okhttp:okhttp:2.5.0'
    implementation 'com.firebaseui:firebase-ui-database:2.1.1'
    implementation 'id.zelory:compressor:2.1.0'
}