flutter doctor - CocoaPods 安装但不工作

flutter doctor - CocoaPods installed but not working

使用 zsh - 用于在 bash
中工作 brew doctor - 您的系统已准备就绪。
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 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  

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

哪个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

使用针对此 post 的建议,我能够使用以下命令重新安装 cocoapods

打开终端

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
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

这对我有用

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

使用 brew 和 gem

  1. 首先由 gem

    卸载

    sudo gem 卸载 cocoapods

  2. 通过 brew 安装 cocoapods

    brew 安装 cocoapods

  3. link 使用 brew

    brew link --overwrite cocoapods

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

如果你使用macOS,系统Ruby不推荐。你不应该使用它。它用于系统特定用途。您需要为用户安装另一个。

brew install rbenv

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

rbenv install 3.1.0

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

rbenv global 3.1

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

最后安装cocoapods

gem install cocoapods

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

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

brew uninstall fastlane
gem install fastlane