CocoaPods那些错

CocoaPods错误集锦

直奔主题,列举出平时使用CocoaPods遇到的一些问题。

问题一:更新gem报错(sudo gem update --system)

  • 错误一:
    * 错误信息:
    * ERROR: While executing gem … (Errno::EPERM)
    Operation not permitted - /usr/bin/xcodeproj

    * 解决办法:
    * 执行sudo gem install -n /usr/local/bin cocoapods命令
    • 错误二:
      • 错误信息:
        • ERROR: While executing gem … (Errno::EPERM)
          Operation not permitted - /usr/bin/update_rubygems
      • 解决办法:
        • 安装Homebrew(Homebrew installs the stuff you need that Apple didn’t.
        /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
        
        • 安装roby
        brew install ruby
        
        • 此时正常的话,会提示:RubyGems system software updated,恭喜你,gem更新成功了!

问题二:pod install报错

错误信息如下:

―――MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
### Command

/usr/local/bin/pod install

### Report
* What did you do?
* What did you expect to happen?
* What happened instead?
### Stack

   CocoaPods : 0.39.0
        Ruby : ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
    RubyGems : 2.5.1
        Host : Mac OS X 10.11.4 (15E65)
       Xcode : 7.2 (7C68)
         Git : git version 2.5.4 (Apple Git-61)
Ruby lib dir : /usr/local/Cellar/ruby/2.3.0/lib
Repositories : artsy - https://github.com/Artsy/Specs.git @ f2334365b5b1a080efa4ded6425001010e5795dd
               master - https://github.com/CocoaPods/Specs.git @ 307eeb6b27f6edde769b6766a886df90db0e208f
### Plugins

cocoapods-plugins : 0.4.2
cocoapods-search  : 0.1.0
cocoapods-stats   : 0.6.2
cocoapods-trunk   : 0.6.4
cocoapods-try     : 0.5.1
### Error
NoMethodError - undefined method `to_ary' for #<Pod::Specification name="Alamofire">
Did you mean?  to_query
……

――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
[!] Oh no, an error occurred.
……
Don't forget to anonymize any private data!

分析

  • CocoaPods与ruby版本
CocoaPods : 0.39.0
     Ruby : ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
  • 那么问题来了,** This is a bug with 0.39 and ruby 2.3.0 - #4689 **

解决办法

如果不是0.39.0 VS 2.3.0
  • 在终端中依次执行以下命令即可
cd ~/.cocoapods/repos
rm -rf master
pod setup
如果是0.39.0 VS 2.3.0
方法一:改变CocoaPods版本
  • 卸载当前版本

    sudo gem uninstall cocoapods

  • 下载指定版本(如:0.39.0)

    sudo gem install cocoapods -v 0.39.0

方法二:改变ruby版本
  • 如何改变ruby版本呢?答案是安装ruby管理器RVM
安装RVM
  • 什么是RVM?

    • RVM:Ruby Version Manager 也就是ruby版本管理工具
  • 安装RVM

    • 在终端中执行命令:

    curl -L https://get.rvm.io | bash -s stable

    • 安装完成之后,载入RVM环境

    source ~/.rvm/scripts/rvm

    • 测试是否安装正确
      查看ruby版本
  • 查询ruby信息

    • 查询已知的ruby版本

    rvm list known

    • 查询已经安装的ruby

    rvm list

  • 安装某版本的ruby

    rvm install 2.0.0

  • 卸载某版本的ruby

    rvm remove 2.3.0

  • 设置ruby版本

    rvm 2.0.0 --default

只要不是0.39.0 VS 2.3.0,应该都可以安装成功的!

问题三:更改ruby版本之后,pod install还是报错!

错误信息如下:

  • 截图
    pod_install
  • 文字描述
# 在终端中执行命令:
pod install
# 错误信息(ruby版本 我刚从2.3.0降到2.0.0)/usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'cocoapods' (>= 0.a) among 6 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/apple/.rvm/gems/ruby-2.0.0-p648:/Users/apple/.rvm/gems/ruby-2.0.0-p648@global', execute `gem env` for more information
	from /usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
	from /usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
	from /usr/local/bin/pod:22:in `<main>'

解决办法

  • 删除cocoapods gem uninstall cocoapods
  • 安装 rvm
  • 重新安装cocoapods gem install cocoapods
  • 执行 pod setup命令

错误四:Podfile文件格式问题

如果你把CocoaPods版本升级到CocoaPods 1.0.0.beta.6,那么之前的Podfile格式就会有问题

  • CocoaPods 1.0.0之前的版本,你的Podfile可能是这样的:
source 'https://github.com/CocoaPods/Specs.git'

link_with 'SwiftMKitDemoTests', 'SwiftMKitDemoUITests'

platform :ios, '8.0'

use_frameworks!

pod 'MJRefresh'
  • CocoaPods 1.0.0之后的版本,你的Podfile可能是这样的:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
platform :ios, '8.0'

target 'SwiftMKitDemo' do
  pod 'MJRefresh'

  target 'SwiftMKitDemoTests' do
    inherit! :search_paths
  end
  target 'SwiftMKitDemoUITests' do
    inherit! :search_paths
  end
end'

五:警告,输入pod关键字

zsh: /usr/local/bin/pod: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: no such file or directory

原因:Mac升级系统导致,当你的Mac系统升级为macOS Catalina 的时候,没有更新cocoapods

解决办法

  1. sudo gem update --system
  2. sudo gem install cocoapods -n/usr/local/bin
    在这里插入图片描述

错误N……

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值