这个装cocoapods 遇到了好多问题,折腾了几天总算装好了,下面说下步骤,省的其他小伙伴踩坑。
1.首先设置ruby源
gem sources -l #查看当前ruby源
gem sources --remove https://rubygems.org/ #移除当前ruby源
gem sources -a https://gems.ruby-china.org/ #设置当前ruby源
2.更新gem
sudo gem update --system
3.安装cocoapods
sudo gem install -n /usr/local/bin cocoapods
下一步执行 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
但是这个方法给了我启发,下载包放到那里后,使用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 ? 然后我想肯定是下载的那个包有问题,原因是下载的包里没有git文件!
然后我就想明白了!于是直接到~/.cocoapods/repos 目录下执行
git clone https://github.com/CocoaPods/Specs.git 然后就等吧,这时要网好,等下载完成后,把下载下的文件夹的名字改为master
然后在项目里就能使用pod install 安装想要的包了
结果运行 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的更新,然后本地的会被覆盖,所以执行不了
到这就简单了,到 ~/.cocoapods/repos/master下执行 git reset HEAD --hard
然后再到项目目录下运行pod install 就没问题了!