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

React Native Android构建报错:mapReleaseSourceSetPaths任务异常求助

React Native Android Release构建错误求助

项目背景

  • 通过以下命令创建React Native TypeScript新项目:
npx react-native init Navigator --template react-native-template-typescript
  • 初始状态下执行cd android && ./gradlew assembleRelease可成功生成Android生产包。

问题详情

  1. 添加项目配置后构建开始报错,其中一个错误通过执行以下命令临时解决:
mkdir android/app/src/main/assets && react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  1. 再次执行bundle命令时出现语法错误:
error index.js: Import statement may only appear at top level in file index.js at 4:2.
Error: Import statement may only appear at top level in file index.js at 4:2
    at minifyCode (/home/rafael/Documents/Library/react-native-error/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-transform-worker/src/index.js:99:13)
  1. 使用已生成的bundle文件,执行cd android && ./gradlew assembleRelease -x bundleReleaseJsAndAssets跳过bundle步骤,仍遇到构建错误:
Execution failed for task ':app:mapReleaseSourceSetPaths'.
> Error while evaluating property 'extraGeneratedResDir' of task ':app:mapReleaseSourceSetPaths'
   > Failed to calculate the value of task ':app:mapReleaseSourceSetPaths' property 'extraGeneratedResDir'.
      > Querying the mapped value of provider(java.util.Set) before task ':app:bundleReleaseJsAndAssets' has completed is not supported

已尝试的解决方案

  • 配置npm脚本(fix:bundle、gradle:clean、build:prod:android)方便命令执行
  • 修改Gradle与Android Gradle Plugin版本
  • 调整babel.config.js和metro.config.js配置

上述操作均未解决问题,寻求技术支持。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 15:45:41