You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Android Studio 3.0.1 DexArchiveMergerException:无法合并dex求助

Fixes for "Unable to merge dex" Error in Android Studio 3.0.1

Hey there, let's work through this dex merging issue you're hitting. This error almost always ties back to duplicate dependencies, outdated build tools, hitting the 64k method limit, or cached build gunk. Here are practical steps to fix it:

  • Clean & Rebuild First
    Start with the simplest fix: head to Build > Clean Project in the top menu, wait for it to finish, then run Build > Rebuild Project. This wipes out any corrupted intermediate build files that might be causing the merge conflict.

  • Hunt for Duplicate Dependencies
    This is the #1 cause. Open your app-level build.gradle and check for dependencies that are included twice—either directly, or indirectly via another library. For example, if you have com.android.support:appcompat-v7:26.1.0 and a third-party library that pulls in an older appcompat version, that's a conflict.
    To spot duplicates easily, run this command in your terminal:

    # macOS/Linux
    ./gradlew app:dependencies
    
    # Windows
    gradlew.bat app:dependencies
    

    This generates a full dependency tree. Once you find a duplicate, exclude it from one of the dependencies like this:

    implementation('com.example.somelibrary:1.0.0') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    
  • Enable MultiDex (If You Hit the Method Limit)
    If your app has over 65,536 methods, you need to turn on MultiDex:

    1. Add the MultiDex dependency to your app-level build.gradle:
      implementation 'com.android.support:multidex:1.0.3'
      
    2. Update your defaultConfig block to enable it:
      android {
          defaultConfig {
              // ... other settings
              multiDexEnabled true
          }
      }
      
    3. If you use a custom Application class, either extend MultiDexApplication or add this method:
      public class MyApplication extends Application {
          @Override
          protected void attachBaseContext(Context base) {
              super.attachBaseContext(base);
              MultiDex.install(this);
          }
      }
      

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

  • Update Build Tools & Gradle Plugin
    Android Studio 3.0.1 uses an older Gradle plugin. Try updating it in your project-level build.gradle to a compatible newer version (stick to versions that work with 3.0.1, or consider upgrading Android Studio if you can):

    buildscript {
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1' // Compatible with 3.0.1
        }
    }
    

    Also, match the buildToolsVersion in your app-level build.gradle to the plugin version—for example, buildToolsVersion "28.0.3".

  • Invalidate Caches & Restart
    Sometimes Android Studio's cached data gets corrupted. Go to File > Invalidate Caches / Restart..., select "Invalidate and Restart", and let the IDE reload. This fixes weird build issues that clean/rebuild misses.

  • Delete Corrupted Build Folders
    If all else fails, delete the .gradle folder in your project root, plus the build folders in both the project and app modules. Then click the Gradle sync icon in the toolbar to re-sync your project.


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

火山引擎 最新活动