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

Android Studio生成APK报错求助:DexArchiveMergerException无法合并dex

Fixing the DexArchiveMergerException in Android Studio 3.0.1 + Gradle 4.1

Hey there, let's break down how to resolve this common dex merging issue you encountered. First, let's restate the error you ran into for clarity:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

This error nearly always traces back to duplicate dependencies, conflicting library versions, or hitting the Android dex method limit. Since you mentioned you already fixed it quickly, here are the most likely actionable fixes that resolve this issue:

  • Enable MultiDex in your project
    If your app exceeds the 64k method limit (a common cause for this error), enabling MultiDex is essential. Add these configurations to your app-level build.gradle:

    android {
        defaultConfig {
            ...
            multiDexEnabled true
        }
    }
    
    dependencies {
        implementation 'com.android.support:multidex:1.0.3'
    }
    

    If you use a custom Application class, make it extend MultiDexApplication, or add this override to handle MultiDex initialization:

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    
  • Resolve duplicate or conflicting dependencies
    Run the command ./gradlew app:dependencies (macOS/Linux) or gradlew.bat app:dependencies (Windows) in your project root to list all dependencies. Look for libraries that appear multiple times with different versions. For example, if you see conflicting versions of com.android.support:appcompat-v7, force a single compatible version with a resolution strategy:

    android {
        ...
        configurations.all {
            resolutionStrategy.force 'com.android.support:appcompat-v7:26.1.0' // Match your target SDK version
        }
    }
    
  • Clean and rebuild your project
    Cached dex files often cause unexpected conflicts. Go to Build > Clean Project in Android Studio, then Build > Rebuild Project. You can also manually delete the .gradle, build, and app/build folders to clear all cached files, then sync your project with Gradle.

  • Update tools (if feasible)
    While you're using Android Studio 3.0.1 and Gradle 4.1, newer versions include fixes for dex merging bugs. If possible, update to a more recent stable Android Studio version and match the Gradle plugin version in your project-level build.gradle (e.g., Android Studio Arctic Fox pairs with Gradle plugin 7.0.2 and Gradle 7.0.2).

Since you resolved this quickly, it's almost certainly one of these steps—most likely enabling MultiDex or fixing conflicting dependencies—that did the trick.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 04:07:12