android studio 3 build无法合并dex

时间:2018-03-02 17:39:51

标签: android firebase android-gradle

你好,突然我的android项目显示了这个错误

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
  

com.android.builder.dexing.DexArchiveMergerException:无法合并dex

在某些日子之前,一切都运转正常,几天之后我又打开了它,并向我展示了这一点 我已经尝试了我在这里找到的所有可能的解决方案,但没有什么工作可以帮助我吗?

这是我的byuild.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.fire.stmtfadmin"
        minSdkVersion 17
        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'
        }
    }
}



allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}






dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.firebase:firebase-storage:11.0.4'
    compile 'com.android.support:cardview-v7:+'
    implementation 'com.google.firebase:firebase-messaging:11.0.4'
    implementation 'com.google.firebase:firebase-database:11.0.4'
    implementation 'com.firebaseui:firebase-ui-database:2.3.0'
    implementation 'com.google.firebase:firebase-auth:11.0.4'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    compile 'id.zelory:compressor:2.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:26.1.0'
    compile 'com.yqritc:recyclerview-multiple-viewtypes-adapter:1.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.StevenDXC:DxLoadingButton:2.0'
    compile 'com.github.dmytrodanylyk:android-morphing-button:98a4986e56' // commit hash
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'br.com.simplepass:loading-button-android:1.12.1'
    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.google.android.gms:play-services-maps:11.0.4'
}




apply plugin: 'com.google.gms.google-services'
// 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
}

3 个答案:

答案 0 :(得分:0)

要使用 11.4.0 版本的Firebase,您需要将maven url添加到build.gradle文件中,如下所示:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

答案 1 :(得分:0)

这可能是因为您使用了以下依赖项:

compile 'com.android.support:cardview-v7:+'

这意味着您要使用最新版本。最新版本27.1.0。

尝试使用:

implementation 'com.android.support:cardview-v7:26.1.0'

永远不要将+用于您的依赖版本。因此,如果将来出现任何问题,您可以重现和调试相同的构建。

答案 2 :(得分:0)

谢谢大家的回复,但唯一对我有用的解决方案是将此行添加到build.gradle(模块:app):

    implementation 'android.arch.lifecycle:extensions:1.1.0'

我希望这会有助于其他人