无法合并Dex错误:Android Studio 3.0

3
我已经尝试了多次解决这个问题,但其他问题中提出的解决方案都没有对我起作用。在将我的代码与队友的代码合并后,由于这个bug,我无法运行我的应用程序。我已经多次清理和重建项目,但错误仍然不断出现:

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

我已经尝试修复gradle警告,更新gradle编译库语句,并在默认配置中加入此标志:
multiDexEnabled true

唯一有效的修复方法是使用上述标志,这使我能够真正运行应用程序,但随之而来的是不同的运行时错误:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.aaronliang.flow_v1, PID: 11780 java.lang.RuntimeException: Unable to get provider >com.google.firebase.provider.FirebaseInitProvider: >java.lang.ClassNotFoundException: Didn't find class >"com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip >file "/data/app/com.example.aaronliang.flow_v1->177.apk"],nativeLibraryDirectories=[/data/app->lib/com.example.aaronliang.flow_v1-177, /vendor/lib, /system/lib]]
以下是我的当前Gradle构建文件:
项目构建:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:3.1.0'

        //classpath 'com.android.tools.build:gradle:2.3.3'
        //classpath 'com.google.gms:google-services:3.1.0'

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

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}

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

应用程序构建:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        multiDexEnabled true
        applicationId "com.example.aaronliang.flow_v1"
        minSdkVersion 15
        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'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.google.firebase:firebase-firestore:11.6.0'
    compile 'com.google.firebase:firebase-auth:11.6.0'
    compile 'com.google.firebase:firebase-core:11.6.0'
    compile 'com.google.android.gms:play-services:11.6.0'
    compile 'com.github.woxthebox:draglistview:1.5.0'
    //compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
    compile 'com.jjoe64:graphview:4.2.1'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }

    }
}

任何帮助都将不胜感激,因为这个项目很快就要结束了!

令人沮丧的错误,有没有人有解决方案? - K Guru
2个回答

2

好的,我成功解决了我的问题!我需要添加这两行代码:

在 app/gradle.build 文件中:

compile 'com.android.support:multidex:1.0.1'

在清单文件中:

android:name="android.support.multidex.MultiDexApplication"

我从这个问题中获取了以下信息:

找不到类“com.google.firebase.provider.FirebaseInitProvider”


0

你的minSdk版本低于20,因此你需要在build.gradle的dependencies中添加compile 'com.android.support:multidex:1.0.1'
来源


清除缓存/重启或添加代码行后重新构建没有帮助吗?尝试将以下内容添加到您的“android”标签中:dexOptions { javaMaxHeapSize "4g" }。这个链接有用吗:https://dev59.com/UlkT5IYBdhLWcg3wAK5E#41444469? - sininen
好奇一下,那个标签是做什么的? - gameCoder95
1
它将您的JVM最大可用内存设置为4G,其中4G表示4 GB。 - sininen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接