解决cocoapods速度慢及搜索报错的问题
学习cocoapods时,碰到两个问题:
pod setup
下载安装非常慢pod search
命令报错,提示找不到相应资源
第一个问题通过更换pod repo镜像解决,第二个重新创建索引解决。
更换pod repo镜像解决安装速度慢的问题
执行pod repo
查看当前repo镜像信息
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/skyue/.cocoapods/repos/master
github是官方镜像,非常的慢。
国内推荐清华大学的镜像,速度不错,且一直保持更新(网上流传的 https://git.coding.net/CocoaPods/Specs.git 镜像已不再更新),修改方式如下:
# 移除当前的源
pod repo remove master
# 克隆清华大学的镜像到本地并命名为master,这一步需要一点时间
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/master
# 最后update
pod repo update
再试试pod repo
看到如下信息,URL已经变了
- Type: git (master)
- URL: https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
- Path: /Users/skyue/.cocoapods/repos/master
在更换repo源后,创建Podfile文件时,首行需加上source字段,指向清华的镜像,如下:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
target 'weather' do
pod 'SVProgressHUD'
end
最后,如果repo刚更新过,那么install或update时,可以忽略repo的更新,提升速度,方式如下:
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
解决Pod search错误提示
使用pod search SVProgressHUD
时出现如下错误:
Unable to find a pod with name, author, summary, or description matching `SVProgressHUD`
解决方法:
首先,执行pod update
更新数据再尝试pod search
。
若依然提示错误,则删除~/Library/Caches/CocoaPods
目录下的search_index.json
文件,再尝试pod search
,将重新创建search_index.json
文件,并返回搜索结果。
参考: