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生产包。
问题详情
- 添加项目配置后构建开始报错,其中一个错误通过执行以下命令临时解决:
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
- 再次执行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)
- 使用已生成的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
相关产品推荐
相关产品推荐

