android - 构建我的Android项目时无法合并dex错误

标签 android gradle dex

我正在尝试构建我的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'
    

    最佳答案

    使用支持库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,而不仅添加该通知,该通知什么也没有。

    关于android - 构建我的Android项目时无法合并dex错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54031766/

    相关文章:

    gradle - 在gradle中同时使用Application和Distribution插件

    android - 无法解析com.google.android.gms.play-service:8.1.0

    Android重新生成优化的dex文件

    android - Android Studio 更新后 Gradle 无法合并 dex

    java - DEX 和 Dalvik 是否支持 Java 二进制兼容性?

    android - 在 Retrofit2.1.0 的构建过程中有没有办法传入 post 请求参数?

    android - 如何在全景/全景模式下直接打开相机?

    android - 如何过滤数据分页 3 Android?

    java - TabLayout setText() 和 setIcon() 无法与自定义 View 一起正常工作

    java - 在Eclipse中使用Gradle导入现有Java项目时不会创建build.gradle