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

React Native初始化iOS环境报错求助:json gem安装失败

React Native初始化报错(json gem安装失败+iOS环境问题)解决步骤

一、解决json 2.6.3 gem安装失败问题

  • 检查并修正Ruby源,确保使用官方源:
    1. 查看当前源:gem sources -l
    2. 移除非官方源(如淘宝源):gem sources --remove [非官方源地址]
    3. 添加官方源:gem sources --add https://rubygems.org/
  • 带编译参数安装json 2.6.3,适配Xcode14.2的编译规则:
    gem install json -v '2.6.3' -- --with-cflags="-Wno-error=implicit-function-declaration"
    
  • 若仍失败,重新安装Ruby2.7.6(用rbenv/rvm),指定openssl路径避免兼容性问题:
    # 以rbenv为例
    RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" rbenv install 2.7.6
    

二、修复iOS环境配置问题

  • 确认Xcode命令行工具配置:
    1. 安装命令行工具:xcode-select --install(已安装会提示)
    2. 设置Xcode路径:sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
    3. 打开Xcode,接受许可协议,进入「Preferences -> Locations」,确保「Command Line Tools」选中Xcode14.2
  • 升级CocoaPods到兼容版本:
    sudo gem install cocoapods
    pod setup
    
  • 分步初始化项目,避免自动安装时的连锁错误:
    1. 初始化项目并跳过自动安装:npx react-native init AwesomeProject --skip-install
    2. 进入项目目录安装依赖:cd AwesomeProject && npm install
    3. 进入iOS目录安装Pods:cd ios && pod install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 09:15:43