【问题标题】:Unable to merge dex error when building my android project构建我的android项目时无法合并dex错误
【发布时间】:2019-05-30 14:26:54
【问题描述】:

我正在尝试构建我的 android 项目并收到错误“无法合并 dex”

我尝试了其他帖子中提到的不同选项。其中一些是

  • 删除未使用的库
  • 将 multidexenabled=true 添加到 gradle 文件
  • 将实现 'com.android.support:multidex:1.0.3' 添加到 gradle 文件中
  • 清理、删除 .gradle 文件夹并重建

问题仍然存在,不确定是什么问题。请分享您的想法。

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

我的 app/build.gradle 文件

            apply plugin: 'com.android.application'

            android {
                compileSdkVersion 27

                defaultConfig {
                    applicationId "app.resta.com.restaurantapp"
                    minSdkVersion 23
                    targetSdkVersion 27
                    versionCode 1
                    versionName "1.0"
                    multiDexEnabled true
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
                compileOptions {
                    targetCompatibility 1.7
                    sourceCompatibility 1.7
                }
            }
            repositories {
                maven { url "https://jitpack.io" }
            }
            dependencies {
                compile fileTree(dir: 'libs', include: ['*.jar'])
                testCompile 'junit:junit:4.12'
                implementation 'com.android.support:appcompat-v7:27.0.2'
                implementation 'com.android.support:design:27.0.2'
                implementation 'com.android.support:recyclerview-v7:27.0.2'

                compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
                implementation 'com.google.firebase:firebase-core:16.0.6'
                implementation 'com.google.firebase:firebase-firestore:17.1.5'
                implementation 'com.google.firebase:firebase-storage:16.0.5'
                implementation 'com.firebaseui:firebase-ui-storage:4.1.0'
                annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
                implementation 'com.android.support:multidex:1.0.3'
            }

            apply plugin: 'com.google.gms.google-services'

【问题讨论】:

    标签: android gradle dex


    【解决方案1】:

    使用支持库27.1.1 构建:

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support:design:27.1.1'
        implementation 'com.android.support:recyclerview-v7:27.1.1'
        implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
        implementation 'com.google.firebase:firebase-core:16.0.6'
        implementation 'com.google.firebase:firebase-firestore:17.1.5'
        implementation 'com.google.firebase:firebase-storage:16.0.5'
        implementation 'com.firebaseui:firebase-ui-storage:4.1.0'
        implementation 'com.android.support:multidex:1.0.3'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
        testImplementation 'junit:junit:4.12'
    }
    

    如果没有,请添加整个 DexArchiveMergerException 而不仅仅是那个通知,它什么也没说。

    【讨论】:

    • 非常感谢。我为此苦苦挣扎了将近一天。没想到会通过增加版本来解决。我能知道你是怎么调试这个的吗?是跟踪错误还是有某种方法可以调试问题?
    • @marin 我只是将它复制并粘贴到 build.gradle 中,然后按照它告诉我的去做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2018-05-04
    相关资源
    最近更新 更多