React Native iOS构建失败求助:RCT-Folly编译错误及脚本警告
React Native iOS构建失败(RCT-Folly SysUio.cpp编译错误)解决方案
核心问题处理:RCT-Folly编译失败
方案1:调整iOS部署目标版本
- 打开Xcode,进入项目Build Settings,搜索
iOS Deployment Target,将版本设置为12.4及以上(RCT-Folly对低版本iOS兼容性较差) - 同步修改Podfile中的平台版本,确保和项目一致:
修改后重新执行platform :ios, '12.4'pod install
方案2:添加RCT-Folly编译兼容参数
- 在Xcode的Pods项目中找到RCT-Folly目标,进入Build Settings
- 搜索
Other C++ Flags,添加-Wno-error=deprecated-declarations和-Wno-error=unused-variable - 也可以在Podfile中添加配置,避免每次
pod install重置参数:
执行post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "RCT-Folly" target.build_configurations.each do |config| config.build_settings["OTHER_CPLUSPLUSFLAGS"] = "-Wno-error=deprecated-declarations -Wno-error=unused-variable" end end end endpod install后重新构建
方案3:锁定RCT-Folly版本(针对RN版本兼容问题)
- 在Podfile中指定RCT-Folly的兼容版本(例如RN 0.68+可指定2021.07.22.00版本):
执行pod 'RCT-Folly', '2021.07.22.00', :modular_headers => truepod install
优化脚本阶段警告(解决重复执行问题)
三个脚本警告是因为未指定输出文件,可手动添加输出路径优化构建缓存:
- Start Packager脚本:
- 进入Xcode项目目标的
Build Phases->Start Packager - 点击
Output Files,添加$(DERIVED_FILE_DIR)/packager-started.txt
- 进入Xcode项目目标的
- Bundle React Native code and images脚本:
- 添加输出文件
$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)和$(DERIVED_FILE_DIR)/react-native-bundle.js
- 添加输出文件
- [CP-User] Config codegen脚本:
- 添加输出文件
$(DERIVED_FILE_DIR)/codegen-config.json
- 添加输出文件
终极清理步骤(以上方案无效时尝试)
- 执行以下命令彻底清理缓存:
rm -rf node_modules && npm install cd ios && rm -rf Pods Podfile.lock *.xcworkspace pod deintegrate && pod install cd .. && watchman watch-del-all rm -rf $TMPDIR/react-native-packager-* rm -rf $TMPDIR/metro-bundler-cache-* - 打开Xcode,执行
Product->Clean Build Folder(快捷键Cmd+Shift+K),再重新构建
内容的提问来源于stack exchange,提问作者Jay-C0de
相关产品推荐
相关产品推荐

