【问题标题】:Unable to merge Dex error: Android Studio 3.0无法合并 Dex 错误:Android Studio 3.0
【发布时间】:2018-05-04 02:39:37
【问题描述】:

我一次又一次地尝试解决此问题,但其他问题中提出的解决方案均不适合我。将我的代码与队友的代码合并后,由于这个错误,我无法运行我的应用程序。我已经多次清理和重建我的项目,但错误仍然不断出现:

错误:任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' 执行失败。 java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并dex

我已经尝试修复 gradle 警告,更新 gradle 编译库语句,并将这个标志放在我的默认配置中:

multiDexEnabled true

产生不同的唯一修复是上面的标志,它允许我实际运行应用程序,但随后发生不同的运行时错误:

E/AndroidRuntime: 致命异常: main 进程:com.example.aaronliang.flow_v1,PID:11780 java.lang.RuntimeException:无法获取提供程序>com.google.firebase.provider.FirebaseInitProvider:>java.lang.ClassNotFoundException:在路径上找不到类>“com.google.firebase.provider.FirebaseInitProvider”: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'
            }
        }

    }
}

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

【问题讨论】:

  • 令人沮丧的错误,任何机构都有解决方案?

标签: java android-studio gradle runtime-error dex


【解决方案1】:

好的,我设法解决了我的问题!我不得不添加这两行:

在 app/gradle.build 中:

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

在清单文件中:

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

我从这个问题中得到了这个:

Didn't find class "com.google.firebase.provider.FirebaseInitProvider"

【讨论】:

    【解决方案2】:

    您的 minSdk 低于 20,因此您必须将 compile 'com.android.support:multidex:1.0.1' 添加到您的 build.gradle dependenciesSource

    【讨论】:

    • 无效缓存/重新启动或在添加行后清理并重建没有帮助?尝试将此添加到您的android 标签:dexOptions { javaMaxHeapSize "4g" }。这有帮助吗:stackoverflow.com/a/41444469 ?
    • 出于好奇,这个标签有什么作用?
    • 它为你的 JVM 设置最大可用内存,4g 表示 4 GB。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多