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

React Native在Genymotion构建失败:Dex归档合并错误求助

Fixing DexArchiveMergerException in React Native on Genymotion

Hey, I’ve dealt with this exact dex merging error when working with React Native and Genymotion before. Since you’ve already added the google() repo and google-services:3.2.1, let’s go through targeted solutions to get your app building again:

1. Enable MultiDex (for method count over 65k)

If your project has a lot of dependencies, you’re probably hitting Android’s 65k method limit. Here’s how to fix it:

  • In your app/build.gradle, add multiDexEnabled true to the defaultConfig block:
    defaultConfig {
        // Your existing config (applicationId, minSdkVersion, etc.)
        multiDexEnabled true
    }
    
  • Add the MultiDex dependency to your dependencies block in the same file:
    dependencies {
        // Other dependencies...
        implementation 'com.android.support:multidex:1.0.3'
    }
    
  • If you have a custom Application class, update it to extend MultiDexApplication. If not, modify your AndroidManifest.xml:
    <application
        android:name="android.support.multidex.MultiDexApplication"
        <!-- Rest of your application attributes -->
    >
    

2. Hunt for duplicate or conflicting dependencies

Most dex merging failures come from conflicting dependency versions (like multiple copies of support libraries or Google services). To diagnose:

  • Run this command in your project root to generate a dependency tree:
    ./gradlew app:dependencies
    
  • Look for duplicate entries (e.g., different versions of com.android.support libraries). Use exclude to remove the conflicting ones from specific dependencies. For example:
    implementation('com.some.library:1.0.0') {
        exclude group: 'com.android.support', module: 'support-v4'
    }
    

3. Clean and rebuild (clear cached junk)

Sometimes stale build cache causes weird merging issues. Let’s wipe it out:

  • Run these commands in your terminal:
    ./gradlew clean
    ./gradlew assembleDebug
    
  • You can also clear Android Studio’s cache by going to File > Invalidate Caches / Restart and selecting "Invalidate and Restart".

4. Update google-services and Gradle plugin versions

The google-services:3.2.1 version you’re using is pretty old. Mismatched versions between the Gradle plugin and Google Services often cause dex issues. Update your root build.gradle to use compatible, stable versions:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.4' // Match this to your project's needs
        classpath 'com.google.gms:google-services:4.3.10' // Newer stable version
    }
}

Make sure the Gradle plugin version aligns with your project’s gradle-wrapper.properties distribution URL.

5. Verify Genymotion emulator setup

Double-check that your Genymotion emulator is running an Android version compatible with your project’s targetSdkVersion. Also, ensure the emulator has all required system components installed (you can check this via the Genymotion settings or SDK Manager).


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:37:23