Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我正在使用 firebase 在 android 工作室中创建壁纸应用程序。 编译时出现错误

Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex Error:com.android.dex.DexException: Multiple dex files define Landroid/arch/lifecycle/LiveData;

我添加了 "multiDexEnabled true" 和 "implementation 'com.android.support:multidex:1.0.3'"

我还清理并重建了我的项目

什么都没发生

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.jimdo.saifstudios.wallpfeb"
    minSdkVersion 19
    targetSdkVersion 26
    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 'com.android.support:multidex:1.0.3'

    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.firebaseui:firebase-ui-database:3.1.2'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support:recyclerview-v7:27.1.0'
    implementation 'com.android.support:cardview-v7:27.1.0'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-database: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'
}

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

查看 firebase-ui 的文档。

https://github.com/firebase/FirebaseUI-Android

对于您使用的版本,您必须使用 com.google.firebase:firebase-database:11.6.2

如果您要在您的应用程序中扩展应用程序。在我的例子中,我通过添加 MultiDex.install(this); 来修复它;到 attachBaseContext(Context context) 方法。

你可以看看: https://developer.android.com/studio/build/multidex.html