1. 程式人生 > >cocoapods:為新專案新增第三方類庫時出錯

cocoapods:為新專案新增第三方類庫時出錯

問題

今天在用 cocoa pods進行新專案配置時, 發現 pod install 為新專案配置匯入第三方類庫時出錯, 自己又特別仔細的檢查了 Podfile 檔案中的每個字元, 沒有發現錯誤.
然後查看了終端中的提示, 如下圖
這裡寫圖片描述
這裡寫圖片描述

解決方案

其實終端中報的錯誤是這樣的:

LoadError - dlopen(/Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/psych.bundle, 9): Library not loaded: /usr/local/lib/libyaml-0.2.dylib
  Referenced from: /Users/MyMac/
.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/psych.bundle Reason: image not found - /Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/psych.bundle

1.我想可能是 cocoa pods 出問題了, 所以想執行 pod update對他進行升級, 發現依然不能正常執行命令, 還是報上面的錯誤提示.

2.也許可能是 repos 的問題, 執行系列命令

cd ~/.cocoapods/repos
rm -rf master
pod setup

發現依然不能正常執行命令, 還是報上面的錯誤提示

3.然後, 自己就認為可能是 cocoapods出問題了, 想解除安裝重新安裝, 所有就要執行下面的命令

sudo gem uninstall cocoapods
sudo gem install cocoapods
pod setup

但我發現當我執行第一條命令時, 終端還會報以下提示:
這裡寫圖片描述

4.按照上面的錯誤網上一頓搜, 各種方法試盡然而, 這時候我才發現原來問題不是這麼簡單, 並不是 cocoapods 的問題.

因為在進行 cocoa pods解除安裝時的錯誤是這樣的:

Error loading RubyGems plugin "/Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/gems/2.0.0/gems/gem-wrappers-1.2.7/lib/rubygems_plugin.rb"
: dlopen(/Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/openssl.bundle Reason: image not found - /Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/openssl.bundle (LoadError)

5.確認是不是rvm的問題, 在 stackoverflow 上發現一篇文章

確認以下三個事情:

1.How did you install ram
2.hit rvm notes and check if it’s installed properly
3.ruby -v, check for the version of ruby present

If you find any issues here, uninstall rvm using rvm implode and also remove ruby. Refer to the rvm installation guide for the use of this command.

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

OR you can try the other way without removing the present rvm installation.

rvm get stable
rvm reinstall 2.0.0

然後, 我就使用了重新安裝了 rvm, 然後就解決了所有的事情.

如果這篇文章還沒有解決你的問題, 另一篇文章可能對你有幫助cocoapods:常見錯誤總結