简体   繁体   English

React-Native:错误:无法为iOS项目安装CocoaPods依赖项,这是该模板所需要的

[英]React-Native: Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template

While executing npx react-native init MyProject I ran into the following error:在执行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.

Which seems to be related to an earlier error displayed:这似乎与之前显示的错误有关:

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 and its CLI seem to all run fine. XCode 及其 CLI 似乎都运行良好。

My configuration:我的配置:

  • MacOS Catalina 10.15.1 (19B88) MacOS 卡特琳娜 10.15.1 (19B88)
  • NPM 6.11.3 NPM 6.11.3
  • React-Native 0.61.4 React-Native 0.61.4
  • XCode 11.2.1 (11B500) XCode 11.2.1 (11B500)

Any leads appreciated.任何线索表示赞赏。

I've found a very similar error reported here , with a solution that suggested:我发现这里报告了一个非常相似的错误,并提供了一个建议的解决方案

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

Reading around seems to suggest that somewhere down the updates line, the XCode CLI tools path was set to an incorrect one. 阅读似乎表明在更新行的某个地方,XCode CLI 工具路径设置为不正确的路径。

Also as @bibin-jaimon suggested in the comments below, I do have multiple versions of XCode on my machine (why? because of https://stackoverflow.com/a/58329901/606351 ).同样正如@bibin-jaimon 在下面的评论中所建议的那样,我的机器上确实有多个版本的 XCode(为什么?因为https://stackoverflow.com/a/58329901/606351 )。

Anyways, problem solved.总之,问题解决了。

Unfortunately the selected answer didn't work for me.不幸的是,选择的答案对我不起作用。 I have Mac OS Catalina 10.15.4, and I have latest version of xcode Version 11.0 (11A420a).我有 Mac OS Catalina 10.15.4,我有最新版本的 xcode 版本 11.0 (11A420a)。 I found some suggestions to reinstall cocopods using homebrew or gem, and at first it didn't work for me, but using it as in below command worked perfectly.我发现了一些使用 homebrew 或 gem 重新安装 cocopods 的建议,起初它对我不起作用,但在下面的命令中使用它效果很好。

sudo gem install cocoapods -n/usr/local/bin须藤宝石安装 cocoapods -n/usr/local/bin

Ali Shirazee's solution worked well for me (thanks.). Ali Shirazee 的解决方案对我来说效果很好(谢谢)。

After running:运行后:

npx react-native init myAppName --template react-native-template-typescript

I got the error:我得到了错误:

error Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template.
Please try again manually: "cd ./myAppName/ios && pod install". CocoaPods documentation: https://cocoapods.org/

Then I went into the folder and ran pod install as suggested in the error message but still got an error during the installation of Flipper-Glog .然后我进入文件夹并按照错误消息中的建议运行pod install ,但在安装Flipper-Glog期间仍然出现错误。

Finally, I've opened Xcode , went into Preferences » Location and selected Xcode 11 from the Command Line Tools select list.最后,我打开Xcode ,进入Preferences » Location并从Command Line Tools select 列表中选择Xcode 11

Xcode » Preferences » Location Xcode » 首选项 » 位置
Xcode » 首选项 » 位置

After that, I simply ran pod install again and it all worked.之后,我再次运行pod install ,一切正常。

I had this issue because I got a new M1 mac, and I found a solution based on this github issue answer and this stackoverflow answer我有这个问题是因为我有一个新的 M1 mac,我找到了一个基于这个 github 问题答案这个 stackoverflow 答案的解决方案

Everything seemed to start working when I installed the ffi gem with the terminal running in Rosetta当我安装 ffi gem 并在 Rosetta 中运行终端时,一切似乎都开始工作了

I resolved this issue,我解决了这个问题,

The situation with me was I recently bought a new mac and installed Xcode along with my development environment.我的情况是我最近买了一个新的 mac 并安装了 Xcode 以及我的开发环境。

However I forgot to configure the Xcode command line tools, when I resolved it worked fine.但是,当我解决它工作正常时,我忘记配置 Xcode 命令行工具。

so follow these simple steps (refer to the screen shot).所以请遵循这些简单的步骤(请参阅屏幕截图)。

Xcode > Preferences > Locations Xcode > 首选项 > 位置

on the command line tools select the option, in my case it was Xcode 11.7 (11....)在命令行工具 select 上的选项,在我的例子中是 Xcode 11.7 (11....)

please note that i had deleted and reinstalled brew, cocoapods and node and it did not work until configured Xcode.请注意,我已删除并重新安装了 brew、cocoapods 和节点,并且在配置 Xcode 之前它无法正常工作。

please refer to the screenshot.请参考截图。

then run sudo npx react-native init yourProjectName然后运行 sudo npx react-native init yourProjectName

在此处输入图像描述

What worked for me on my Mac M1 machine was:在我的 Mac M1 机器上对我有用的是:

Before hand, download Xcode.在此之前,请下载 Xcode。

First: I went to the Applications through Finder and clicked into the Utilities folder.首先:我通过 Finder 进入应用程序,然后单击实用程序文件夹。 Inside the folder, I right clicked the Terminal icon and clicked Get Info from the popup.在文件夹中,我右键单击终端图标,然后从弹出窗口中单击获取信息 After, another popup should have appeared and I checked the box, Open using Rosetta .之后,应该会出现另一个弹出窗口,我选中了Open using Rosetta框。

Next, I did the same with Xcode.接下来,我对 Xcode 做了同样的事情。 I went into the Applications folder, right clicked the Xcode icon, and checked Open using Rosetta我进入 Applications 文件夹,右键单击 Xcode 图标,并选中Open using Rosetta

After I went into the terminal and copied in these commands:在我进入终端并复制这些命令后:

sudo gem install cocoapods

Finally,最后,

sudo gem install ffi

Afterwards I ran:后来我跑了:

npx react-native init HelloRN

And I did not get an error.而且我没有收到错误。

Hopes this helps!希望这会有所帮助!

Update repo then reinstall:更新 repo 然后重新安装:

$ pod repo update
$ pod install

In my case, the link between homebrew and cocoapods had broken I'm guessing during the catalina upgrade.就我而言,自制软件和 cocoapods 之间的链接在 catalina 升级期间已经中断。

Following command fixed it: brew link --overwrite cocoapods以下命令修复了它: brew link --overwrite cocoapods

For myself non of the above worked apart from this one which seemed to install a lot of missing Flipper kits and some other missing dependencies -对我自己来说,除了这个似乎安装了很多缺失的 Flipper 套件和其他一些缺失的依赖项之外,上述任何一项都不起作用 -

 pod install --repo-update

"brew install cocoapods" worked for me. “brew install cocoapods”对我有用。 I'am using M1 14"我正在使用 M1 14"

In my case, the problem was because I haven't cocoapods installed.就我而言,问题是因为我没有安装 cocoapods。

brew install cocoapods

This solved my problem.这解决了我的问题。

This was also not working for me.这也不适合我。 I have tried every answer given in this thread and none of them worked for me.我已经尝试了这个线程中给出的每个答案,但没有一个对我有用。 I was trying on Intel Mac not the Apple Silicon Mac我在尝试 Intel Mac 而不是 Apple Silicon Mac

If similar thing happens to anyone else then try this.如果类似的事情发生在其他人身上,那么试试这个。

sudo gem install cocoapods

Make sure you don't have empty space in any folder names leading to your project directory (example 'My Documents').确保在指向项目目录的任何文件夹名称中没有空白空间(例如“我的文档”)。 Its simple, but this is how i fixed the error.它很简单,但这就是我修复错误的方式。

After using the command from the selected message, I got the following error:使用所选消息中的命令后,出现以下错误:

[!] Error installing Flipper-PeerTalk
[!] /usr/bin/git clone https://github.com/priteshrnandgaonkar/peertalk.git /var/folders/hw/0fc3vqbn4t34rk73tk1r9lwr0000gn/T/d20201016-18847-1n36woh --template= --single-branch --depth 1 --branch v0.0.3

Cloning into '/var/folders/hw/0fc3vqbn4t34rk73tk1r9lwr0000gn/T/d20201016-18847-1n36woh'...
fatal: unable to access 'https://github.com/priteshrnandgaonkar/peertalk.git/': Could not resolve host: github.com

Then I used A Khudairy's solution and it worked very well.然后我使用了 A Khudairy 的解决方案,效果很好。 Thanks for everyone.谢谢大家。

(Just reporting this because, maybe, someone can find this new error on this process and now this page can be googled with this solution) (只是报告这个,因为也许有人可以在这个过程中找到这个新错误,现在这个页面可以用这个解决方案在谷歌上搜索)

It gave me the same error and also said:它给了我同样的错误,还说:

*Please try again manually: "cd ./myApp/ios && pod install"* 

which I did.我做了。 It turned out that my CocoaPods version is below the required version.原来我的CocoaPods版本低于要求的版本。 Your problem could also be this.你的问题也可能是这样的。

*[!] `React` requires CocoaPods version `>= 1.10.1`, which is not satisfied by your current version, `1.9.1`.*

Then i upgraded the Cocoapods by:然后我通过以下方式升级了 Cocoapods:

brew upgrade cocoapods

finally, for my case, it can work by:最后,就我而言,它可以通过以下方式工作:

  1. Try to open up Xcode, and it will ask to install the required dependencies/component for it to work (usually due to some update)尝试打开 Xcode,它会要求安装所需的依赖项/组件以使其工作(通常是由于一些更新)
  2. Install / Reinstall Cocoapods, type sudo gem install cocoapods安装/重新安装 Cocoapods,输入sudo gem install cocoapods
  3. Try npx react-native init AwesomeProject hopefully it works:)尝试npx react-native init AwesomeProject希望它有效:)

Just a hint: for those of you using the M1 Macs, pod install won't work.只是一个提示:对于那些使用 M1 Mac 的人, pod install将不起作用。 You should use arch -x86_64 pod install as stated in this issue您应该使用arch -x86_64 pod install本期所述

Removing environment variable LDFLAGS and CPPFLAGS in ~/.bashrc or ~/.zshrc solve it for me.删除~/.bashrc~/.zshrc中的环境变量 LDFLAGS 和 CPPFLAGS 为我解决了这个问题。

Then in terminal use source ~/.bashrc or source ~/.zshrc to make those changes in the terminal session.然后在终端中使用source ~/.bashrcsource ~/.zshrc .zshrc 在终端 session 中进行这些更改。

WARNING: pod update is dangerous because you'd update all of your dependencies to the latest version警告:pod update 很危险,因为您会将所有依赖项更新到最新版本

For me doing pod update instead of pod install worked!对我来说,做pod update而不是pod install有效!

I was getting an error with Flipper-Glog我在使用Flipper-Glog时遇到错误

CocoaPods could not find compatible versions for pod "Flipper-Glog": In Podfile: Flipper-Glog (= 0.5.0.4) CocoaPods 找不到 pod“Flipper-Glog”的兼容版本:在 Podfile:Flipper-Glog (= 0.5.0.4)

Running pod install manually after the npx react-native init failed to install was not working so I added pod update and it installed not only Flipper-Glog but also all the others successfully.npx react-native init安装失败后手动运行pod install不起作用,所以我添加了pod update ,它不仅安装了Flipper-Glog ,还成功安装了所有其他的。

I have tried above all possible solution but failed:我已经尝试了所有可能的解决方案,但失败了:

then i made some changes and it worked perfectly.然后我做了一些改变,效果很好。

just goto project/ios/podfile只需转到项目/ios/podfile

open podfile and add bellow line打开 podfile 并添加以下行

use_flipper!() --> just underneath/below to this line use_flipper!() --> 就在这条线的下方/下方

use_flipper.({'Flipper' => '0.125.0'}) --> // you need to add this line use_flipper.({'Flipper' => '0.125.0'}) --> // 你需要添加这一行

or或者

you can get help from this link below您可以从此链接获得帮助

https://fbflipper.com/docs/getting-started/react-native-ios/https://fbflipper.com/docs/getting-started/react-native-ios/

in my case, I just cd into ios in my project folder and run bundle install就我而言,我只是在我的项目文件夹中 cd 进入 ios 并运行bundle install

i had similar problem.我有类似的问题。 the solution that worked for updating the pod用于更新 pod 的解决方案

pod repo update

then ran然后跑

pod install

it gave a waring on mac m1 and worked ok.它在mac m1上发出警告并且工作正常。

 Do not use "pod install" from inside Rosetta2 (x86_64 emulation on arm64)

If you are using Apple silicons如果您使用的是 Apple 硅

first run sudo gem uninstall cocoapods and then run brew install cocoapods首先运行sudo gem uninstall cocoapods然后运行brew install cocoapods

make sure you have homebrew https://brew.sh/确保你有自制https://brew.sh/

make sure you are not using the Ruby that the system is operating.确保您没有使用系统正在运行的 Ruby。

ruby is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installs another version in parallel can cause all kinds of trouble. ruby 是 keg-only,这意味着它没有符号链接到 /usr/local,因为 macOS 已经提供了这个软件并且并行安装另一个版本会导致各种麻烦。

so you need to install ruby for example with homebrew:所以你需要用自制软件安装 ruby:

  • run跑步
brew install ruby 
  • If you need to have ruby first in your PATH, run:如果您需要在 PATH 中首先安装 ruby,请运行:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
  • For compilers to find ruby you may need to set:为了让编译器找到 ruby,您可能需要设置:
  export LDFLAGS="-L/usr/local/opt/ruby/lib" >> ~/.zshrc
  export CPPFLAGS="-I/usr/local/opt/ruby/include" >> ~/.zshrc
  • then install cocoa pods by running gem:然后通过运行 gem 安装 cocoa pods:
sudo gem install -n /usr/local/bin cocoapods

If you already have the latest version of CocoaPods installed, try running pod install again.如果您已经安装了最新版本的CocoaPods ,请尝试再次运行 pod install。 If the issue persists, try running pod install --repo-update .如果问题仍然存在,请尝试运行pod install --repo-update

cd ios

pod install --repo-update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React-native Error: Failed to install CocoaPods dependencies for iOS project, 这是这个模板所需要的 - React-native Error : Failed to install CocoaPods dependencies for iOS project, which is required by this template 错误:无法安装此模板所需的 iOS 项目的 CocoaPods 依赖项 - Error: Failed to install CocoaPods dependencies for iOS project, which is required by this template 无法为 iOS 项目 React-Native 安装 CocoaPods 依赖项 - Failed to install CocoaPods dependencies for iOS project React-Native 错误无法为 ios 项目安装 CocoaPods 依赖项。 反应原生 - Error Failed to install CocoaPods dependencies for ios project. React Native 初始化 react-native 项目时无法安装 cocoapods - failure to install cocoapods when initializing a react-native project 编译源iOS依赖项以实现react-native - Compile source iOS dependencies for react-native React-Native IOS 构建在 pod 安装时出错。? - React-Native IOS build giving error on pod install.? 安装react-native-custom-segmented控件,需要安装ios框架才能进行react-native项目 - Installing react-native-custom-segmented control, need to install ios framework to react-native project 显示使用Cocoapods的Xcode项目的所有本机iOS依赖关系/框架 - Show All Native iOS Dependencies/Frameworks for an Xcode Project That Uses Cocoapods CodePush React-Native iOS失败 - CodePush react-native ios failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM