cocoapods 安装(每次都会遇见不同的问题 简单记录一下)

 

错误1

:cocoapods ERROR: Error installing cocoapods:

    ERROR: Failed to build gem native extension.

一气之下重新安装pod,成功解决报错,下面为安装不步骤,记录一下

1、安装Homebrew

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

 

2、通过brew安装ruby

(1)命令:brew install ruby

(2)配置环境变量:

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile

source ~/.bash_profile

 

3、安装 CocoaPods

(1)sudo gem install -n /usr/local/bin cocoapods

(2)pod repo update --verbose

4、替换镜像源

(1)移除:sudo gem sources--removehttps://rubygems.org/

(2)添加:sudo gem sources--addhttps://gems.ruby-china.com

(3)查看:gem sources -l

 

 

错误记录:

cocoapods报错 undefined method `deprecator‘ for ActiveSupport:Module (NoMethodError)

升级或者重装cocoapods报错

/usr/local/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 /usr/local/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:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
    from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
    from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/lib/cocoapods.rb:9:in `<top(required)>'
    from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
    from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
    from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.13.0/bin/pod:36:in `<top (required)>'
    from /usr/local/bin/pod:25:in `load'
    from /usr/local/bin/pod:25:in `<main>'

从错误上看Cocoapods 使用activesupport 中方法找不到对应的方法

没有指定确切的版本,并且上一个版本(7.1.0)有一个错误

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

gem 'activesupport', '~> 7.0', '<= 7.0.8'

这样写可能会报错,我们换个思路,直接删除activesupport库,下载旧版本

直接删除会报 因cocoapods 使用无法删除,

You have requested to uninstall the gem:
    activesupport-7.1.0

所以我们先下载旧版本

sudo gem install activesupport -v 7.0.8

查看版本:gem list

abbrev (default: 0.1.1)
activesupport (7.1.0, 7.0.8)
addressable (2.8.5)

...

删除7.1.0

sudo gem uninstall activesupport

Select gem to uninstall:
 1. activesupport-7.0.8
 2. activesupport-7.1.0
 3. All versions

输入2

再执行pods操作,发现正常使用

 

 

posted @ 2023-10-19 09:09  宁静暖风  阅读(297)  评论(0编辑  收藏  举报