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

升级macOS与Xcode后React Native命令行运行失败求助

解决React Native命令行运行报错找不到MacOSX SDK的问题

问题场景

将macOS从12.3升级到13.1,Xcode从13.1升级到14.1并安装Command Line Tools后,React Native应用可通过Xcode正常运行,但使用react-native run-ios命令行启动时出现以下错误:

2022-12-13 16:36:47.584 xcodebuild[3616:20381] Writing error result bundle to /var/folders/zn/6l6295m57kb3vn_8pyn8xtbr0000gn/T/ResultBundle_2022-13-12_16-36-0047.xcresult
xcodebuild: error: SDK "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" cannot be located.
xcrun: error: Failed to determine realpath of '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk' (errno=No such file or directory)
xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -find simctl 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
error Could not get the simulator list from Xcode. Please open Xcode and try running project directly from there to resolve the remaining issues.
Error: Command failed: xcrun simctl list --json devices
2022-12-13 16:36:47.584 xcodebuild[3616:20381] Writing error result bundle to /var/folders/zn/6l6295m57kb3vn_8pyn8xtbr0000gn/T/ResultBundle_2022-13-12_16-36-0047.xcresult
xcodebuild: error: SDK "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" cannot be located.
xcrun: error: Failed to determine realpath of '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk' (errno=No such file or directory)
xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -find simctl 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH

    at checkExecSyncError (node:child_process:828:11)
    at Object.execFileSync (node:child_process:863:15)

临时执行export SDKROOT=$(xcrun -sdk macosx --show-sdk-path)后可正常启动,但关闭终端后问题复现,已尝试sudo xcode-select --reset和sudo xcode-select --install无效。

解决方案

1. 永久设置SDKROOT环境变量

问题根源是系统默认的SDKROOT仍指向旧版本的MacOSX12.3.sdk,而Xcode 14.1已使用MacOSX13.sdk,需将SDKROOT永久写入shell配置文件:

  • 若使用zsh(macOS默认shell):
    1. 打开配置文件:open ~/.zshrc
    2. 在文件末尾添加:export SDKROOT=$(xcrun -sdk macosx --show-sdk-path)
    3. 保存文件后执行:source ~/.zshrc使设置立即生效
  • 若使用bash:
    1. 打开配置文件:open ~/.bash_profile(或~/.bashrc)
    2. 同样添加上述export语句
    3. 执行:source ~/.bash_profile(或对应文件)生效

2. 确认Xcode Command Line Tools路径正确

执行以下命令检查当前Xcode路径:

xcode-select -p

若输出不是/Applications/Xcode.app/Contents/Developer,执行以下命令修正:

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

3. 验证设置有效性

重启终端后,执行以下命令查看SDKROOT是否正确指向当前Xcode的SDK路径:

echo $SDKROOT

预期输出应为类似:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.sdk,此时再运行react-native run-ios即可正常启动应用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 21:40:24