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

Expo自定义开发客户端Android构建失败(Run gradlew报错)

Expo自定义开发客户端Android构建失败:重复Dex类与StackOverflowError解决办法

核心错误分析

构建时触发两个致命错误:

  1. 重复Dex类冲突:com.bumptech.glide.GeneratedAppGlideModuleImpl类同时出现在react-native-fast-image和expo-image的Android构建产物中,导致Dex合并失败
  2. 栈溢出错误:构建过程中抛出java.lang.StackOverflowError,通常由Gradle内存不足或依赖递归调用引发

解决方案

一、解决重复Dex类冲突

方案1:移除其中一个冲突依赖

两个库均基于Glide实现图片加载,且自动生成了相同的Glide模块类,直接移除其中一个即可解决冲突:

  • 卸载react-native-fast-image:
    npm uninstall react-native-fast-image
    # 或 yarn remove react-native-fast-image
    
  • 清理项目缓存后重新构建:
    npx expo prebuild --clean
    npx expo run:android
    

方案2:排除重复依赖(保留双库场景)

若必须同时使用两个库,需在Android构建配置中排除其中一个库的Glide依赖:

  1. 打开android/app/build.gradle文件
  2. 在dependencies块中添加排除规则(二选一):
    排除react-native-fast-image的Glide依赖:
    implementation(project(':react-native-fast-image')) {
        exclude group: 'com.github.bumptech.glide'
    }
    
    或排除expo-image的Glide依赖:
    implementation(project(':expo-image')) {
        exclude group: 'com.github.bumptech.glide'
    }
    
  3. 清理Gradle缓存:
    cd android && ./gradlew clean
    

二、解决StackOverflowError

通过调整Gradle内存配置缓解栈溢出问题:

  1. 打开android/gradle.properties文件
  2. 修改或添加JVM内存配置:
    org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    
  3. 清理Gradle构建缓存:
    cd android && ./gradlew cleanBuildCache
    

完整操作流程

  1. 选择上述任一方案处理重复Dex类问题
  2. 调整Gradle内存配置
  3. 执行全量缓存清理:
    npx expo prebuild --clean
    cd android && ./gradlew clean cleanBuildCache
    cd ..
    
  4. 重新启动构建:
    npx expo run:android
    # 或EAS云端构建
    eas build --profile development --platform android
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 07:30:48