在 Apple Silicon (M1) 上安装 pod 时出错。

12

我正在运行的命令是

brew install cocoapods     

警告:cocoapods 1.11.2_2 已安装并且是最新版本。 若要重新安装 1.11.2_2,请运行: brew reinstall cocoapods ~ % alias pod='arch -x86_64 pod'

下面是错误信息:

/opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/conflict.rb:47:in `conflicting_dependencies': undefined method `request' for nil:NilClass (NoMethodError)

    [@failed_dep.dependency, @activated.request.dependency]
                                       ^^^^^^^^
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/exceptions.rb:61:in `conflicting_dependencies'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/exceptions.rb:55:in `initialize'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver.rb:193:in `exception'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver.rb:193:in `raise'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver.rb:193:in `rescue in resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver.rb:191:in `resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/request_set.rb:411:in `resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/request_set.rb:423:in `resolve_current'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:230:in `finish_resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:287:in `block in activate_bin_path'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:285:in `synchronize'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:285:in `activate_bin_path'
    from /opt/homebrew/Cellar/cocoapods/1.11.2_2/libexec/bin/pod:25:in `<main>'
/opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:317:in `raise_error_unless_state': Unable to satisfy the following requirements: (Gem::Resolver::Molinillo::VersionConflict)

- `minitest (= 5.14.2)` required by `user-specified dependency`
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:299:in `block in unwind_for_conflict'
    from <internal:kernel>:90:in `tap'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:297:in `unwind_for_conflict'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:682:in `attempt_to_activate'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:254:in `process_topmost_state'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:182:in `resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver/molinillo/lib/molinillo/resolver.rb:43:in `resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/resolver.rb:190:in `resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/request_set.rb:411:in `resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems/request_set.rb:423:in `resolve_current'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:230:in `finish_resolve'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:287:in `block in activate_bin_path'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:285:in `synchronize'
    from /opt/homebrew/Cellar/ruby/3.1.1/lib/ruby/3.1.0/rubygems.rb:285:in `activate_bin_path'
    from /opt/homebrew/Cellar/cocoapods/1.11.2_2/libexec/bin/pod:25:in `<main>'

我已经卸载并重新安装了RUBY和COCOAPODS。现在出现以下错误:
/Library/Ruby/Site/2.6.0/rubygems.rb:265:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
    from /Library/Ruby/Site/2.6.0/rubygems.rb:284:in `activate_bin_path'
    from /usr/local/bin/pod:23:in `<main>'

1
有可能您安装了两个不同的 Ruby 版本,一个是通过 Home Brew 安装的,另一个是苹果为自己使用而安装在 /Library/Ruby 中的。请在终端中尝试运行 which ruby 命令。我建议 不要 使用 Brew 作为开发环境,而是使用 rbenv,但这取决于个人情况。 - the Tin Man
6个回答

30

我通过删除CocoaPods并重新安装解决了这个问题。

gem cleanup
brew uninstall cocoapods
sudo gem uninstall cocoapods
sudo gem install cocoapods -n /usr/local/bin
sudo gem install cocoapods-user-defined-build-types
pod install --repo-update

1
太棒了!谢谢 @Alfred - undefined

1

我遇到了同样的错误。我正在使用rvm(RubyVersionManager)。请确保您使用的是与第一次运行安装时相同的Ruby版本。如果您是第一次运行安装,请确保您没有使用系统版本的Ruby(它是非常旧的版本)。

在我的情况下,我尝试在版本3.0.0上运行pod install,但我应该在3.1.2上运行它,更改版本后问题得到解决。


1

尝试删除您的yarn.lock或package.lock文件。希望这样可以解决问题。

如果这不起作用,请尝试rvm install ruby-3.1.1rvm --default use ruby-3.1.1


对我来说很有效,使用rvm安装Ruby并将其设置为默认版本。这将更改版本以及路径。 - Ashish Singh

1

当我运行pod install时,遇到了与这个问题相同的情况,而不是在安装Cocoapods时。我使用的是ruby 3.0.0版本,但通过安装3.0.3版本后,按照Cocoapods的步骤操作后,pod install开始正常工作了。如果您也遇到了类似的问题,可以参考这篇GitHub评论来解决。


1

我在使用 Mac M1 安装 React Native CLI 时遇到了类似的问题,以下是解决方案:

gem cleanup
brew uninstall cocoapods
sudo gem uninstall cocoapods
sudo gem install cocoapods -n /usr/local/bin
sudo gem install cocoapods-user-defined-build-types

然后通过运行以下命令检查pod版本

pod --version


-1

M1上安装CocoaPods

我使用HomeBrew https://brew.sh/

以下是操作步骤。

在终端中复制并运行以下命令

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

如果您收到任何警告,例如(警告:/opt/homebrew/bin不在您的PATH中。 有关如何为Homebrew配置您的shell的说明 可以在下面的“下一步”部分中找到。) 那么请忽略这两个命令。

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/shourob.datta/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

现在安装Cocoapods
brew install cocoapods

现在安装pods,定位项目

Pod install

完成


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