颤振医生 - CocoaPods 已安装但无法正常工作

Mat*_*ias 5 homebrew cocoapods flutter

使用 zsh - 用于在 bash
brew doctor 中工作 - 您的系统已准备好进行 brew 。
颤振医生给出了这个错误

[!] 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  
Run Code Online (Sandbox Code Playgroud)

sudo gem 安装 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  
Run Code Online (Sandbox Code Playgroud)

我无法纠正上述错误 - 有什么建议吗?

哪个吊舱

/Users/puser/.rvm/rubies/ruby-2.5.1/bin/pod
Run Code Online (Sandbox Code Playgroud)

哪个宝石

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}
}
Run Code Online (Sandbox Code Playgroud)

哪个红宝石

/Users/puser/.rvm/rubies/ruby-2.5.1/bin/ruby
Run Code Online (Sandbox Code Playgroud)

小智 14

使用酿造和宝石

  1. 首先通过gem卸载

    sudo gem 卸载 cocoapods

  2. 通过brew安装cocoapods

    酿造安装cocoapods

  3. 使用brew链接

    酿造链接——覆盖cocoapods


Mat*_*ias 10

使用这篇文章的建议,我能够在安装 cocoapods 时使用以下命令重新
安装 cocoapods gem native extension error

打开终端

curl -L https://get.rvm.io | bash -s stable
Run Code Online (Sandbox Code Playgroud)

重新打开终端

rvm install ruby-2.6

rvm use ruby-2.6.5

rvm --default use 2.6.5
Run Code Online (Sandbox Code Playgroud)

然后这按预期安装了 cocoapods

sudo gem install cocoapods
Run Code Online (Sandbox Code Playgroud)

  • 谢谢。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.2”和“sudo gem install cocoapods”对我有用 (7认同)
  • 谢谢。你救我!我想给你提供更多信息。如果您在 m1 上使用 Flutter。那么你应该像这样安装它。`rvm install ruby​​-2.6 --with-out-ext=fiddle` 在我的例子中,安装的版本是 2.6.6。所以也许你改变了这个特定的版本。 (4认同)

Has*_*jmi 7

首先安装brewMac 版的包管理器。 https://brew.sh

如果您使用 macOS,不建议使用系统 Ruby。你不应该使用它。它供系统特定使用。您需要为用户安装另一个。

brew install rbenv
Run Code Online (Sandbox Code Playgroud)

然后安装最新版本的ruby。今天是 3.1.0

rbenv install 3.1.0 --verbose
Run Code Online (Sandbox Code Playgroud)

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

rbenv global 3.1.0
Run Code Online (Sandbox Code Playgroud)

关闭终端并再次重新打开它,以影响更改。

最后安装cocoapods

gem install cocoapods
Run Code Online (Sandbox Code Playgroud)

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

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

brew uninstall fastlane
gem install fastlane
Run Code Online (Sandbox Code Playgroud)

如果您在构建 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