CocoaPods安裝及使用

1、更新指定的第三方庫命令
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update

2、安裝指定版本的cocoapods
sudo gem install cocoapods --version 0.39.0

3、如果之前裝過cocopods,最好先卸載掉,卸載命令:
$ sudo gem uninstall cocoapods

4、先查看本地安裝過的cocopods相關(guān)東西,命令如下:
$ gem list --local | grep cocoapods
會(huì)顯示如下:

cocoapods-core (0.39.0)
cocoapods-downloader (0.9.3)
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)

然后逐個(gè)刪除吧:
$ sudo gem uninstall cocoapods-core
$ sudo gem uninstall cocoapods-downloader
etc...

5、cocoapods安裝流程

  1. 查看ruby:ruby -v
  2. 查看源:gem sources -l
  3. 移除源:gem sources --remove https://rubygems.org/
  4. 設(shè)置新的源:gem sources -a https://ruby.taobao.org/
  5. 驗(yàn)證是否替換成功:gem sources -l
  6. 升級gem:sudo gem update --system
  7. 安裝CocoaPods(OS X 10.11以前):sudo gem install cocoapods
  8. 安裝CocoaPods(OS X 10.11以后):sudo gem install -n /usr/local/bin cocoapods
  9. pod setup(cd ~/.cocoapods/跳轉(zhuǎn)到目錄下用命令du -sh *查看下載進(jìn)度)

6、cocoapods升級遇到的問題

1)運(yùn)行sudo gem update --system報(bào)錯(cuò)

Updating rubygems-update
ERROR:  While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems

原因:brew更新或重裝的時(shí)候?qū)е碌奈覀冸娔X上沒有ruby環(huán)境了,需要重新安裝一下
解決方案:安裝ruby:brew install ruby
安裝Homebrew:

// 網(wǎng)址:http://brew.sh/
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2)執(zhí)行pod update遇到的問題
出現(xiàn):“Performing a deep fetch of themasterspecs repo to improve future performance”。
解決方案: 刪除索引庫,重新安裝Pod,執(zhí)行終端命令:

rm -rf ~/.cocoapods/repos
pod setup

3)執(zhí)行pod setup遇到的問題1
問題1:

[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master
  Cloning into 'master'...
  error: RPC failed; result=56, HTTP code = 200
  fatal: The remote end hung up unexpectedly
  fatal: early EOF
  fatal: index-pack failed

解決方案:

cd 任意的一個(gè)使用Git的項(xiàng)目
   #執(zhí)行
   git repack --max-pack-size=500m -a -d
   pod setup

問題2:

[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master
Cloning into 'master'...
error: RPC failed; curl 56 SSLRead() return error -36
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

解決辦法:

You can try adding it manually in ~/.cocoapods/repos or via pod repo add.
自己按照提示在終端輸入以下命令:
pod repo add master https://github.com/CocoaPods/Specs.git
還是報(bào)錯(cuò)!
在終端輸入以下命令:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developers
后面的地址你可以打開Xcode顯示包內(nèi)容,找到那個(gè)文件夾拖到終端里面。

4)pod search 搜索類庫失敗的解決辦法

  1. 執(zhí)行pod setup

其實(shí)在你安裝CocoaPods執(zhí)行pod install時(shí),系統(tǒng)會(huì)默認(rèn)操作pod setup,然而由于中國強(qiáng)大的墻可能會(huì)pod setup不成功。這時(shí)就需要手動(dòng)執(zhí)行pod setup指令,如下:

  • 終端輸入:pod setup
    會(huì)出現(xiàn)Setting up CocoaPods master repo,稍等幾十秒,最底下會(huì)輸出Setup completed。說明執(zhí)行pod setup成功。
  • 如果pod search操作還是搜索失敗,如下:
    終端輸入:pod search AFNetworking
    輸出:Unable to find a pod with name, author, summary, or descriptionmatching 'AFNetworking'這時(shí)就需要繼續(xù)下面的步驟了。
  1. 刪除~/Library/Caches/CocoaPods目錄下的search_index.json文件

pod setup成功后,依然不能pod search,是因?yàn)橹澳銏?zhí)行pod search生成了search_index.json,此時(shí)需要?jiǎng)h掉。
終端輸入:rm ~/Library/Caches/CocoaPods/search_index.json
刪除成功后,再執(zhí)行pod search
執(zhí)行pod search
終端輸入:pod search afnetworking(不區(qū)分大小寫)
輸出:Creating search index for spec repo 'master'.. Done!,稍等片刻······就會(huì)出現(xiàn)所有帶有afnetworking字段的類庫。

5)pod install庫失敗

Cloning into 'master'...
error: RPC failed; curl 56 SSLRead() return error -9806
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

解決辦法:

$ brew remove git
$ brew remove curl
$ brew install openssl
$ brew install --with-openssl curl
$ brew install --with-brewed-curl --with-brewed-openssl git
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容