這個裝cocoapods 遇到了好多問題,折騰了幾天總算裝好了,下面說下步驟,省的其他小伙伴踩坑。
1.首先設(shè)置ruby源
gem sources -l #查看當前ruby源
gem sources --remove https://rubygems.org/ #移除當前ruby源
gem sources -a https://gems.ruby-china.org/ #設(shè)置當前ruby源
2.更新gem
sudo gem update --system
3.安裝cocoapods
sudo gem install -n /usr/local/bin cocoapods
下一步執(zhí)行 pod setup,然后坑就來了,試了好多次都失敗
報錯如下:
[!] /usr/bin/git clonehttps://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
試了各種方式也解決不了,包括直接下載Cocoapods包放到~/.cocoapods/repos/ 下并命名為master
但是這個方法給了我啟發(fā),下載包放到那里后,使用pod search AFNetworking能搜到東西了,但是在項目里使用pod install 還是會出錯
錯誤如下:
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master-1`.
You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
然后我就納悶了,~/.cocoapods/repos 目錄下不是有一個master了嗎?為什么還要添加一個 master-1 ? 然后我想肯定是下載的那個包有問題,原因是下載的包里沒有g(shù)it文件!
然后我就想明白了!于是直接到~/.cocoapods/repos 目錄下執(zhí)行?
git clone https://github.com/CocoaPods/Specs.git ?然后就等吧,這時要網(wǎng)好,等下載完成后,把下載下的文件夾的名字改為master
然后在項目里就能使用pod install 安裝想要的包了
結(jié)果運行 pod install ?的時候又出問題了,崩潰啊
Address$ pod install
From https://github.com/CocoaPods/Specs
a4f097d..43b2172master-> origin/master
error: Your local changes to the following files would be overwritten by merge:
Specs/5/f/3/TypeWriting/0.0.1/TypeWriting.podspec.json
Specs/6/6/2/EmptyKit/3.0.0/EmptyKit.podspec.json
Specs/f/0/4/TangramKit/1.0.0/TangramKit.podspec.json
Please commit your changes or stash them before you merge.
Aborting
Updating a4f097d..43b2172
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master-1`.
You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
就是說有幾個文件改動了,pod install 會拉取cocoapods的更新,然后本地的會被覆蓋,所以執(zhí)行不了
到這就簡單了,到 ~/.cocoapods/repos/master下執(zhí)行 git reset HEAD --hard?
然后再到項目目錄下運行pod install 就沒問題了!