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

React Native CLI无法运行iOS模拟器,检测正常仍报错求助

React Native iOS构建失败问题
  • 执行 npx react-native doctor 检测,iOS相关项全部显示正常(绿色对勾)
  • 启动Metro服务器:npm start,执行 npm run ios 后模拟器正常打开,但出现冗长构建错误
  • 进入ios目录执行 pod install,过程中出现异常

解决建议

1. 清理依赖与缓存

  • 进入ios目录,删除Pods文件夹和Podfile.lock:
    cd ios
    rm -rf Pods Podfile.lock
    
  • 清除CocoaPods全局缓存:
    pod cache clean --all
    
  • 返回项目根目录,重置npm依赖:
    cd ..
    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    

2. 重新安装Pods

  • 进入ios目录,确保使用兼容的Ruby版本(React Native推荐2.6+),更新仓库后重装:
    cd ios
    # 若使用rbenv,指定版本示例:rbenv local 2.7.6
    pod install --repo-update
    

3. 检查Xcode配置

  • 打开ios目录下的.xcworkspace文件:
    • 确认项目Build Settings中的iOS Deployment Target与Podfile里的配置一致
    • 检查Signing & Capabilities是否配置了有效的开发者账号
    • 执行Xcode缓存清理:Command + Shift + K,再尝试重新构建

4. 调整Podfile配置

  • 打开Podfile,确保平台版本正确:
    platform :ios, '14.0' # 需与Xcode部署目标匹配
    
  • 若使用M1/M2芯片,在Podfile末尾添加兼容配置:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
        end
      end
      react_native_post_install(installer)
      __apply_Xcode_12_5_M1_post_install_workaround(installer)
    end
    
    保存后重新执行pod install

5. 重置Metro并重新构建

  • 关闭现有Metro服务器,带缓存重置启动:
    npm start -- --reset-cache
    
  • 重新执行iOS构建:
    npm run ios
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 18:25:18