M1芯片iMac重启后React Native iOS项目编译失败求助
解决方案
M1芯片环境适配修复
- 用Rosetta模式运行终端:右键终端应用→显示简介→勾选「使用Rosetta打开」,重启终端后进入项目
ios目录,执行:pod deintegrate && pod install - 校验Xcode命令行工具路径:执行
xcode-select -p确认路径正确,若指向旧版本,执行:sudo xcode-select -s /Applications/Xcode.app/Contents/Developer - 在
ios/Podfile末尾添加架构适配配置,重新执行pod install:post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'arm64' config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO' end end end
修复「RCTAppDelegate.h找不到」问题
- 检查Xcode头文件路径:打开Xcode→选中项目Target→Build Settings→Header Search Paths,确保包含以下路径并设为「recursive」:
$(SRCROOT)/../node_modules/react-native/React$(SRCROOT)/../node_modules/react-native/ReactCommon
- 手动触发RN链接:执行
npx react-native link(0.70+版本虽自动链接,但极端情况可修复路径异常)
解决xcodebuild错误码70(设备超时)
- 重置iOS模拟器:打开模拟器→菜单栏「模拟器」→「内容与设置」→「重置」
- 重启模拟器服务:关闭所有模拟器和Xcode,执行:
killall -9 com.apple.CoreSimulator.CoreSimulatorService - 校验模拟器名称:执行
xcrun simctl list devices复制正确的模拟器名称,替换命令中的参数后重新执行:npm run ios -- --simulator="你的模拟器名称"
兜底方案
- 重装适配M1的CocoaPods:先卸载旧版本
sudo gem uninstall cocoapods,再通过Homebrew安装brew install cocoapods,最后进入ios目录执行pod setup && pod install
内容的提问来源于stack exchange,提问作者user4016522
相关产品推荐
相关产品推荐

