Flutter doctor - CocoaPods已安装但无法工作

19

使用 zsh - 以前使用 bash 工作
brew doctor - 您的系统已准备好进行 brew。
flutter doctor 出现此错误

[!] Xcode - develop for iOS and macOS (Xcode 12.2)
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods. For more info, see https://github.com/flutter/flutter/issues/14293.
      To re-install CocoaPods, run:
        sudo gem install cocoapods  

使用sudo命令安装CocoaPods

Gives this error  
dyld: Library not loaded: /usr/local/opt/gmp4/lib/libgmp.3.5.2.dylib  
  Referenced from: /Users/puser/.rvm/rubies/ruby-2.5.1/bin/ruby  
  Reason: image not found  
zsh: abort      sudo gem install cocoapods  
我无法解决上述错误-有什么建议吗?

哪个pod?

/Users/puser/.rvm/rubies/ruby-2.5.1/bin/pod

哪个 gem

gem () {
    \typeset result
    (
        \typeset rvmrc
        rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc") 
        if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
        then
            rvm_rvmrc_files+=("${rvm_prefix}/.rvmrc") 
        fi
        for rvmrc in "${rvm_rvmrc_files[@]}"
        do
            [[ -s "${rvmrc}" ]] && source "${rvmrc}" || true
        done
        unset rvm_rvmrc_files
        command gem "$@"
    ) || result=$? 
    hash -r
    return ${result:-0}
}

哪个ruby

/Users/puser/.rvm/rubies/ruby-2.5.1/bin/ruby
12个回答

52

使用这篇帖子的建议,我成功地通过以下命令重新安装了CocoaPods。
安装 CocoaPods 时出现 gem native extension 错误

打开终端

curl -L https://get.rvm.io | bash -s stable
重新打开终端。
rvm install ruby-2.6

rvm use ruby-2.6.5

rvm --default use 2.6.5

然后按预期安装了cocoapods

sudo gem install cocoapods

1
谢谢。这对我帮助很大。 - anticafe
4
谢谢,你救了我!我想给你额外的信息。 如果你在 m1 上使用 Flutter,那么你应该像这样安装它。 rvm install ruby-2.6 --with-out-ext=fiddle在我的情况下,安装的版本是 2.6.6。所以也许你需要改变这个特定的版本。 - Seong Jun
1
太棒了!经过数小时的努力,终于成功了。 - Adeolaex
7
谢谢。rvm网站推荐使用\curl -sSL https://get.rvm.io | bash -s stable下载,之后我安装了rvm install ruby-2.7.2。确保你没有使用Homebrew安装CocoaPods,如果有,请使用brew uninstall cocoapods卸载。然后,rvm --default use 2.7.2sudo gem install cocoapods对我起作用了。 - biniam
1
非常感谢,这对我有用。 - urmish patel
显示剩余4条评论

11

使用brew和gem

  1. 首先使用gem卸载

    sudo gem uninstall cocoapods

  2. 使用brew安装cocoapods

    brew install cocoapods

  3. 使用brew链接

    brew link --overwrite cocoapods


6

首先在 Mac 上安装 brew 包管理器。 https://brew.sh

如果您使用的是 macOS,则不建议使用系统自带的 Ruby。因为它仅供系统特定用途使用,您需要为用户安装另一个 Ruby。

brew install rbenv

然后安装最新版本的 Ruby。截至今天,它是 3.1.0。

rbenv install 3.1.0 --verbose

然后设置全局 Ruby 版本,以在所有 shell 中使用

rbenv global 3.1.0

关闭终端并重新打开,以使更改生效。

最后安装CocoaPods。

gem install cocoapods

正如您所看到的,您不使用sudo命令。因为您没有覆盖系统特定配置。当您需要使用sudo命令时,意味着您正在做一些应该避免的事情。

如果您正在使用fastlane,并且仍然抱怨cocoapods,即使cocoapods已经正确安装,请重新安装fastlane

brew uninstall fastlane
gem install fastlane

如果在构建3.1.0时遇到了Ruby zlib扩展的问题:

  1. brew install zlib
  2. LDFLAGS=-L/usr/local/opt/zlib/lib CPPFLAGS=-I/usr/local/opt/zlib/include rbenv install 3.1.0

2
curl -L https://get.rvm.io | bash -s stable
rvm install ruby-2.6
rvm use ruby-2.6.5
rvm --default use 2.6.5
sudo gem update
sudo gem install ffi
brew install libffi
sudo gem install cocoapods
pod setup

这对我有用。

1
我看到很多人建议使用rvm来管理Ruby。我尝试了一下,但失败了。事实上,Flutter只是想让我安装CocoaPods。为什么不直接安装CocoaPods呢?最后我还是选择了使用它。
brew install cocoapods

解决了这个问题

1
使用最新版本的Flutter(需要ruby 2.7.2),所以以下步骤适用于我:
1. curl -L https://get.rvm.io | bash -s stable 2. rvm install ruby-2.7.2 3. rvm --default use 2.7.2 4. sudo gem install cocoapods

使用了2.7.2和2.7.8版本,但不幸的是仍然无法正常工作。 - undefined

0

我正在使用搭载 M1 芯片的 MacBook Pro(2020 年款),以下步骤可行:


url -L https://get.rvm.io | bash -s stable

rvm install ruby-2.6

rvm reinstall ruby-2.6.6 

rvm use ruby-2.6.6

rvm --default use 2.6.6

sudo gem install cocoapods

最后,您可以运行flutter doctor进行确认。

flutter doctor

输出将会是这样的...

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.4 21F79 darwin-arm, locale
    en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version
    32.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.68.1)
[✓] Connected device (1 available)
[✓] HTTP Host Availability

0
sudo gem install -n /usr/local/bin cocoapods

只需运行此命令即可安装最新版本的coc


0
请安装最新版本的Ruby以解决此问题。 使用以下命令:
rvm install ruby

rvm use ruby

rvm --default use

0

sudo gem uninstall cocoapods
rvm install 2.6.5
sudo gem install cocoapods

sudo gem 卸载 cocoapods
rvm 安装 2.6.5
sudo gem 安装 cocoapods


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接