首页 > 解决方案 > React-Native:错误:无法为 iOS 项目安装 CocoaPods 依赖项,这是此模板所需的

问题描述

在执行时npx react-native init MyProject我遇到了以下错误:

✖ Installing CocoaPods dependencies (this may take a few minutes)
error Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.

这似乎与显示的早期错误有关:

checking for arm-apple-darwin-gcc... /Library/Developer/CommandLineTools/usr/bin/cc -arch armv7 -isysroot 
checking whether the C compiler works... no
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: unable to lookup item 'Path' in SDK 'iphoneos'

XCode 及其 CLI 似乎都运行良好。

我的配置:

任何线索表示赞赏。

标签: iosreact-nativenpm

解决方案


我发现这里报告了一个非常相似的错误,并提供了一个建议 的解决方案:

sudo xcode-select --switch /Applications/Xcode.app

阅读似乎表明在更新行的某个地方,XCode CLI 工具路径设置为不正确的路径。

同样正如@bibin-jaimon 在下面的评论中所建议的那样,我的机器上确实有多个版本的 XCode(为什么?因为https://stackoverflow.com/a/58329901/606351)。

总之,问题解决了。


推荐阅读