新安装或者更新遇到问题,建议先检查一下是否安装,且版本对应
(安装或更新版本最好用梯子,特别是rvm)
homebrew->rvm->ruby->Xcode-select
gem sources 保留这一个源:https://gems.ruby-china.com/
以上存在部分存在依赖性,最后再检查本地是否存在多个版本Xcode
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
pod setup的本质就是将https://github.com/CocoaPods/Specs上的Specs项目clone到/Users/用户名/.cocoapods/repos目录下。若此目录下已有Specs项目,则会将项目更新到最新的状态。由于Specs很大,容易导致pod setup失败。这时就需要我们手动安装Specs。若直接从github上下载zip文件,由于缺少git文件,会导致cocoa pods不使用。若用git clone,由于文件过大,容易导致失败。
git clone https://github.com/CocoaPods/Specs.git cocoapods ~/.cocoapods/repos
Cloning into 'cocoapods'...
remote: Counting objects: 894306, done.
remote: Compressing objects: 100% (56/56), done.
^Cceiving objects: 6% (53659/894306), 10.39 MiB | 216.00 KiB/s
但是由于包体积较大,甚至700M之多,可能导致失败:
Cloning into 'cocoapods'...
remote: Enumerating objects: 242, done.
remote: Counting objects: 100% (242/242), done.
remote: Compressing objects: 100% (204/204), done.
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
其实我们无需全部 clone 下来,可以只 clone 最近一个 commit 的全部代码就可以了。
git clone --depth=1 https://github.com/CocoaPods/Specs.git master
$ git clone --depth=1 https://github.com/CocoaPods/Specs.git cocoapods ~/.cocoapods/repos
Cloning into 'cocoapods'...
remote: Enumerating objects: 888536, done.
remote: Counting objects: 100% (888536/888536), done.
remote: Compressing objects: 100% (541327/541327), done.
remote: Total 888536 (delta 227354), reused 853003 (delta 224134), pack-reused
Receiving objects: 100% (888536/888536), 131.22 MiB | 73.00 KiB/s, done.
Resolving deltas: 100% (227354/227354), done.
Checking connectivity: 888536, done.
Checking out files: 100% (407411/407411), done.
另外删除trunk
git remove repos trunk
chen@ChendeMacBook-Pro repos % ls
cocoapods master
我的master是国内的源,下载速度飞起,用起来很方便
如果实在受不了github下载速度的话,建议更换repo源,国内还是比较知名的如阿里云的,清华的。(gitee的貌似不更新了)
https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
https://code.aliyun.com/Magi/CocoaPods.git
https://gitclub.cn/CocoaPods/Specs.git 推荐
https://www.jianshu.com/p/58ecb7fc7269
当然更换之后,其他项目的Podfile 里面source也要对应的上才可以。