You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio开发Firebase壁纸应用遇Dex合并失败求助

Fixing "Multiple dex files define Landroid/arch/lifecycle/LiveData$1" in Firebase Wallpaper App

Hey there, let's work through this dex merge error you're hitting. The Multiple dex files define LiveData$1 message tells us there's a duplicate dependency conflict—even with multidex enabled, duplicate classes will still break your build. Here's how to fix it step by step:

1. Identify the conflicting dependencies

First, we need to find out which libraries are pulling in duplicate copies of the LiveData class. Run this command in your project's root directory:

  • On macOS/Linux: ./gradlew app:dependencies
  • On Windows: gradlew.bat app:dependencies

Search the output for android.arch.lifecycle:livedata (or androidx.lifecycle:livedata if you're using AndroidX). You'll likely see that Firebase (or one of its associated libraries, like Firebase UI) is introducing a version of LiveData that conflicts with the one you're explicitly adding, or vice versa.

2. Exclude duplicate dependencies

Once you spot the conflicting library, add an exclude rule to your build.gradle (Module level) to remove the duplicate LiveData dependency. For example, if Firebase Auth is pulling in the conflicting LiveData:

implementation 'com.google.firebase:firebase-auth:20.0.4' {
    exclude group: 'android.arch.lifecycle', module: 'livedata'
}

Repeat this for any other libraries that show up with duplicate LiveData entries.

3. Align to AndroidX (if you haven't already)

If you're still using the old Support Library, mixing it with Firebase's modern AndroidX dependencies is a common source of conflicts. Here's how to switch:

  1. Open your gradle.properties file and add these lines:
    android.useAndroidX=true
    android.enableJetifier=true
    
    Jetifier automatically converts old Support Library dependencies to AndroidX equivalents.
  2. Replace any Support Library lifecycle dependencies with AndroidX versions. For example:
    // Replace this (Support Library)
    // implementation 'com.android.support:multidex:1.0.3'
    // implementation 'android.arch.lifecycle:livedata:1.1.1'
    
    // With this (AndroidX)
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    

4. Clean deeper than just "Clean Project"

Sometimes the standard Clean/Rebuild isn't enough. Try these steps:

  • Delete the .gradle folder in your project's root directory
  • Delete the build folders in both your project root and the app module
  • Re-sync your Gradle files (click the "Sync Project with Gradle Files" button in Android Studio)
  • Rebuild your project

5. Check for manual library duplicates

Double-check your app/libs folder to make sure you haven't added a .jar or .aar file for LiveData (or any lifecycle-related library) that's also being pulled in via Gradle dependencies. If you find one, remove it.

After following these steps, your build should resolve the duplicate LiveData class issue and merge dex successfully.

内容的提问来源于stack exchange,提问作者Saif

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:03:47