将 Cocoapods 更新到 1.13.0 后,它会抛出错误

回答 5 浏览 1.2万 2023-10-05

我将 Cocoapods 更新到 1.13.0 并在调用 pod install 后抛出错误:

conversions.rb:108:in 'class:Array': undefined method 'deprecator' for ActiveSupport:Module (NoMethodError)

bundler: failed to load command: pod (/opt/homebrew/opt/bin/rbenv/versions/3.2.2/bin/pod)
/opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError)

  deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
                                                          ^^^^^^^^^^^
Did you mean?  deprecate_constant
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:8:in `<top (required)>'
    from <internal:/opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/lib/cocoapods.rb:9:in `<top (required)>'
    from <internal:/opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/bin/pod:36:in `<top (required)>'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/bin/pod:25:in `load'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/bin/pod:25:in `<top (required)>'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `load'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:23:in `run'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:492:in `exec'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:28:in `start'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.10/libexec/bundle:45:in `block in <top (required)>'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.10/libexec/bundle:33:in `<top (required)>'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/bin/bundle:25:in `load'
    from /opt/homebrew/opt/bin/rbenv/versions/3.2.2/bin/bundle:25:in `<main>'

我该如何修复它?

Alex Motor 提问于2023-10-05
5 个回答
#1楼 已采纳
得票数 51

安装 Cocoapods 时会发生这种情况。

运行以下命令修复

sudo gem uninstall activesupport

这可能会要求您选择需要卸载的版本。如果选择版本。

然后安装工作版本

sudo gem install activesupport -v 7.0.8
Danushka herath 提问于2023-10-05
我使用asdf和本地gem,所以不需要sudogem uninstall activesupportgem install activesupport -v 7.0.8并将Gemfile修改为gem 'activesupport', '~> 7.0', '>= 7.0.8'blyscuit 2023-10-06
我实际上做了你们所说的,所以当我尝试卸载 activesupport 时,它向我发出了一个危险的警告,表明存在依赖项,如果我确定要卸载它,我没有卸载它,所以这就是我所做的我直接通过sudo gem install activesupport -v 7.0.8安装,然后我执行了卸载命令sudo gem uninstall activesupport,它列出了我要卸载的版本,我选择了最后一个版本。对我来说这是最安全的方法。Feki Hamza 2023-10-14
我厌倦了 MacBook 中仍然面临的问题。执行 pod install 或 pod --version 时出现相同的错误ganesh manoj 2023-10-18
@ganeshmanoj 你的 activesupport 版本是什么?Danushka herath 2023-10-18
#2楼
得票数 28

看起来 Cocoapods 使用 activesupport 没有指定确切的版本,并且上一个版本 (7.1.0) 有一个错误。

找到解决方法。限制为activesupport (7.0.8) 的最新稳定版本。

gem 'activesupport', '~> 7.0', '<= 7.0.8'
Alex Motor 提问于2023-10-05
您错过了安装关键字。 gem install 'activesupport', '~> 7.0', '<= 7.0.8'Syed Danial 2023-10-10
这种方法将其添加到 CI 的 gemfile 中。但你是对的Alex Motor 2023-10-10
#3楼
得票数 9

将此行添加到项目文件夹的 Gemfile 中

gem 'activesupport', '~> 7.0.8'
  1. cd ios 导航到 ios 文件夹。
  2. bundle install 安装 Bundler
  3. bundle update activesupport 更新主动支持版本
  4. bundle exec pod install 安装由 CocoaPods 管理的 iOS 依赖项。
Twinkle Patel 提问于2023-10-07
#4楼
得票数 6

我的解决方案是在根目录下的 Gemfile 中用下面的内容替换原来的gem 'cocoapods'

gem 'cocoapods', '~> 1.12'
gem 'activesupport', '>= 6.1.7.3', '< 7.1.0'

然后,cd ios进入ios文件夹并运行下面的这些。它会像以前一样工作。我对这部分不熟悉。也许有些命令是不必要的。但这对我有用。

1. bundle update
2. bundle install
3. pod repo update
4. bundle exec pod install
Yucheng 提问于2023-10-07
对于 Flutter,我修复了它: 1. 在 iOS 文件夹中打开 Gemfile 2. 添加:gem "cocoapods", '~> 1.12.1' gem'activesupport', '~> 7.0.8'Yauheni Prakapenka 2023-10-10
#5楼
得票数 1

这是一个已知错误,并且已由 cocoapods 团队修复,但尚未发布。

您可以通过添加 1 行代码轻松修复它,直到下一个版本:

  1. 使用 VSCode 或其他内容打开/opt/homebrew/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/lib/cocoapods.rb

  2. 在第 7 行其他“require active_support/...`.”之上添加 require 'active_support'

Demo

  1. (sudo) 保存文件并再次运行gem install cocoapods

💡 这不是必需的,并且与此问题相关,但您也可以更新您的 ruby​​ 和 gem 文件按照此链接 以防止进一步的错误

Mojtaba Hosseini 提问于2023-10-09
Mojtaba Hosseini 修改于2023-10-09