将字节码转换为 dex 时出错:原因:com.android.dex.DexException:

Error converting bytecode to dex: Cause: com.android.dex.DexException:

我正在开发一个 android 应用程序并且 gradle 构建工作正常但是现在当我构建我的 android 项目时,gradle 构建失败并显示以下错误

Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Landroid/arch/core/internal/SafeIterableMap$Entry; Message{kind=ERROR, text=Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Landroid/arch/core/internal/SafeIterableMap$Entry;, sources=[Unknown source file], original message=UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/arch/core/internal/SafeIterableMap$Entry; , tool name=Optional.of(Dex)}

注: 我已经在我的 build.gradle(app) 中添加了 multiDexEnabled true 并且我还清理并重建了项目

我正在使用 Android studio 3.1

我的 build.gradle(app) 低于

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    multiDexEnabled true
    applicationId "atnd.mdadil2019.myprojectname"
    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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
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.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

//3rd party libraries
implementation 'cn.pedant.sweetalert:library:1.3'
implementation 'com.github.jlmd:AnimatedCircleLoadingView:1.1.5@aar'
implementation 'com.google.android.gms:play-services-places:11.8.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'android.arch.persistence.room:runtime:1.0.0-alpha1';
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha1';
implementation 'com.google.android.gms:play-services-location:11.8.0'
}


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

我的build.gradle(项目)如下

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.2.1'
   }
}

allprojects {
repositories {
    google()
    jcenter()
    mavenCentral()
    maven {
        url "http://dl.bintray.com/jlmd/maven"
    }
    maven { url 'https://maven.google.com' }
}
}

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

你的错误是你有 2+ 个声明 android.arch.core.internal.SafeIterableMap$Entry.

的依赖项

首先,将您的 Room 依赖项从 1.0.0-alpha1 升级到 1.0.0。 Room 已经有几个月没有 alpha 了。

如果这不能解决您的问题,您将需要 运行 一份 Gradle 依赖报告并找到您从哪里获得 2+ 个版本的 android.arch 库,然后制作确保您获得了这些库的最新版本。