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

React Native Android构建失败::app:dexBuilderRelease任务执行出错求助

解决React Native Android构建:app:dexBuilderRelease失败问题

问题说明

构建React Native Android Release版本时遇到Execution failed for task ':app:dexBuilderRelease'错误,核心原因是react-native-openai库引入的jetified-openai-client-jvm.jar和jetified-openai-core-jvm.jar在Dex转换过程中失败,同时伴随无法解析:app:detachedConfiguration4配置文件的问题。

使用的依赖版本:

  • react: ^18.2.0
  • react-native: ^0.72.5
  • react-native-openai: ^0.6.1

已尝试清理项目、重新构建、同步Gradle,问题未解决。

可行解决方案

1. 启用Core Library Desugaring

Android默认的Dex编译器对Java 8+字节码支持有限,启用Desugaring可以处理这些不兼容的字节码:
在android/app/build.gradle中修改配置:

android {
    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
}

2. 排除冲突的JVM依赖

react-native-openai引入的JVM版本依赖可能和Android环境不兼容,尝试排除这些依赖:
在android/app/build.gradle的dependencies块中添加:

implementation(project(':react-native-openai')) {
    exclude group: 'com.theokanning.openai-gpt3-java', module: 'client'
    exclude group: 'com.theokanning.openai-gpt3-java', module: 'core'
}

如果需要,可手动添加适配Android的同系列依赖版本(需确认版本兼容性)。

3. 升级react-native-openai库

旧版本的react-native-openai可能存在兼容性bug,升级到最新稳定版:

npm install react-native-openai@latest --save

升级后重新执行Gradle同步和构建。

4. 调整Dex编译配置

增加Dex编译的堆内存并强制使用D8编译器:
在android/app/build.gradle中添加:

android {
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }

    compileOptions {
        useDexArchive = true
    }
}

5. 彻底清理并重新Jetify依赖

Jetify缓存可能导致异常,执行以下命令:

cd android
./gradlew clean
./gradlew jetify
./gradlew assembleRelease

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 17:41:16