将字节码转换为dex:原因:com.android.dex.DexException:多个dex文件定义

时间:2018-05-07 21:03:53

标签: java android firebase geofire

  

错误:将字节码转换为dex时出错:原因:com.android.dex.DexException:多个dex文件定义了Landroid / arch / lifecycle / LiveData $ LifecycleBoundObserver;

我的gradle文件

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.ayoubdesigner101.Sinbad.sealling"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.google.firebase:firebase-database:11.0.4'
implementation 'com.google.firebase:firebase-crash:11.0.4'
implementation 'com.google.firebase:firebase-storage:11.0.4'
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:2.3.0'

compile 'com.google.android.gms:play-services:11.0.4'
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.android.support:cardview-v7:27.1.1'
compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
compile 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.bumptech.glide:glide:4.6.1'
compile 'com.firebase:geofire-android:2.1.1'
}

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

**这是我得到的错误**

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/arch/lifecycle/LiveData$LifecycleBoundObserver;
Error:com.android.dex.DexException: Multiple dex files define Landroid/arch/lifecycle/LiveData$LifecycleBoundObserver;
Error:  at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error:  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error:  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error:  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error:  at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error:  at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error:  at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error:  at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error:  at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error:  at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error:  at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Landroid/arch/lifecycle/LiveData$LifecycleBoundObserver;
Information:BUILD FAILED in 14s
Information:15 errors
Information:0 warnings
Information:See complete output in console

1 个答案:

答案 0 :(得分:1)

您需要upgrade your Firebase Ui个依赖项以及GeoFire

一旦你这样做,ensure compatibles between it and the other Google and Firebase versions

而不是:play-services:11.0.4,请compile the specific dependencies of Google Play you actually are going to use。这种依赖性就是它们的全部,它会减慢你的构建,增加你不会使用的库。

如果您已将任何JAR文件添加到libs文件夹中,通常也会出现此错误。对于上面提到的类,JAR必须是一个android支持库,例如Android Architecture