CocoaPods錯誤集錦
直奔主題,列舉出平時使用CocoaPods遇到的一些問題。
問題一:更新gem報錯(sudo gem update --system)
- 錯誤一:
* 錯誤信息:
* <font color='red'>ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj</font>
* 解決辦法:
* 執(zhí)行sudo gem install -n /usr/local/bin cocoapods命令- 錯誤二:
- 錯誤信息:
- <font color='red'>ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems</font>
- <font color='red'>ERROR: While executing gem ... (Errno::EPERM)
- 解決辦法:
- 安裝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 - <a >#4689</a> **
解決辦法
如果不是0.39.0 VS 2.3.0
- 在終端中依次執(zhí)行以下命令即可
cd ~/.cocoapods/repos
rm -rf master
pod setup
如果是0.39.0 VS 2.3.0
方法一:改變CocoaPods版本
-
卸載當(dāng)前版本
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
- 在終端中執(zhí)行命令:
curl -L https://get.rvm.io | bash -s stable- 安裝完成之后,載入RVM環(huán)境
source ~/.rvm/scripts/rvm-
測試是否安裝正確
查看ruby版本.png
-
查詢ruby信息
- 查詢已知的ruby版本
rvm list known- 查詢已經(jīng)安裝的ruby
rvm list -
安裝某版本的ruby
rvm install 2.0.0 -
卸載某版本的ruby
rvm remove 2.3.0 -
設(shè)置ruby版本
rvm 2.0.0 --default
只要不是
0.39.0VS2.3.0,應(yīng)該都可以安裝成功的!
問題三:更改ruby版本之后,pod install還是報錯!
錯誤信息如下:
-
截圖
pod_install_ruby報錯.png - 文字描述
# 在終端中執(zhí)行命令:
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 - 執(zhí)行
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'

