我正在开发一个Android应用程序并且gradle构建工作正常但现在当我构建我的android项目时,gradle构建失败并显示以下错误
将字节码转换为dex时出错: 原因:com.android.dex.DexException:多个dex文件定义了Landroid / arch / core / internal / SafeIterableMap $ Entry; 消息{kind = ERROR,text =将字节码转换为dex时出错: 原因:com.android.dex.DexException:多个dex文件定义Landroid / arch / core / internal / SafeIterableMap $ Entry;,sources = [未知源文件],原始消息= UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException:多个dex文件定义了Landroid / arch / core / internal / SafeIterableMap $ Entry; ,工具名称= 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
}
答案 0 :(得分:2)
您的错误是您有2个以上声明android.arch.core.internal.SafeIterableMap$Entry
的依赖项。
首先,将您的房间依赖关系从1.0.0-alpha1
升级到1.0.0
。几个月来,房间已经不合时宜了。
如果这不能解决您的问题,您将需要运行Gradle依赖关系报告并找到您获得2个以上版本的android.arch
库的位置,然后确保您获得这些库的最新版本