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

升级依赖后出现DexArchiveMergerException:Unable to merge dex错误求助

Fixing Dex Merge Error After Upgrading Firebase Dependencies

Hey there, let's work through this dex merge issue you're facing. The error you're seeing is almost always tied to dependency version conflicts or duplicate library entries, especially when mixing Firebase and Google Play Services dependencies. Here's how to fix it step by step:

1. Remove the Full Play Services Dependency

You’re using the complete play-services package (com.google.android.gms:play-services:12.0.1), which is a massive bundle that includes every Play Services module. This is unnecessary (you already have maps and gcm explicitly added) and is causing version clashes with your newer Firebase/Play Services dependencies (like play-services-maps:15.0.1).

Delete this line from your app-level build.gradle:

implementation 'com.google.android.gms:play-services:12.0.1'

2. Align All Firebase & Play Services Dependency Versions

Firebase and Google Play Services dependencies must use compatible versions to avoid dex merge failures. Let’s update your Play Services entries to match the version range that works with your Firebase setup:

Your current Firebase dependencies are on 16.x/17.x, so adjust your Play Services lines to:

implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'

(Note: FirebaseUI 4.0.0 is fully compatible with Firebase 16.0.0-16.0.1 and Play Services 15.0.1-16.0.0, so this alignment will keep everything in sync.)

3. Ensure MultiDex is Fully Configured

You’ve enabled multiDexEnabled = true, but you need to complete the MultiDex setup:

Add the MultiDex library dependency to your app-level build.gradle:

implementation 'com.android.support:multidex:1.0.3'

Then, update your Application class in one of two ways:

  • Extend MultiDexApplication directly:
    public class MyApplication extends MultiDexApplication {
        // Your existing application code here
    }
    
  • If you can’t extend MultiDexApplication, override attachBaseContext:
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    

Don’t forget to reference your custom Application class in AndroidManifest.xml if you haven’t already.

4. Clean & Rebuild Your Project

After making these changes:

  • Go to Build > Clean Project in Android Studio
  • Then run Build > Rebuild Project
  • Alternatively, use the command line: ./gradlew clean assembleDebug

5. Check for Hidden Duplicate Dependencies

If the error still persists, generate a dependency tree to spot conflicting libraries:

./gradlew app:dependencies

Look for libraries that appear with multiple versions, and exclude the older ones using the exclude directive in your dependencies (e.g., exclude group: 'com.google.android.gms', module: 'play-services-base').


After following these steps, your dex merge error should be resolved. Let me know if you hit any snags along the way!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:51:14