公司项目中使用的第三方更新了SDK,一直是用cocoapods来依赖第三方的,但是更改了版本号之后执行pod install一直卡住无法安装,关键问题在于cocoapods也是从github中clone第三方的项目到本地作为依赖的,git clone不了,导致整个pod依赖不上,所以需要梯子来从github clone 项目:
写在前面:
可以尝试先把git更新一下看能否解决问题,不能的话再看下面
- 设置全局git配置从github clone项目都走本地代理:
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
地址和端口号查看本地ss配置
之后再执行pod install看看是否可行
- 如果以上不可行,则需要卸载重装cocoapods,使用国内镜像
首先查看已安装cocoapods相关项目
gem list --local | grep cocoapods
如下:
cocoapods (1.7.4)
cocoapods-core (1.7.4)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.3.1)
cocoapods-try (1.1.0)
卸载所有:
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-deintegrate
sudo gem uninstall cocoapods-downloader
sudo gem uninstall cocoapods-plugins
sudo gem uninstall cocoapods-search
sudo gem uninstall cocoapods-stats
sudo gem uninstall cocoapods-trunk
sudo gem uninstall cocoapods-try
安装rvm:
curl -L https://get.rvm.io | bash -s stable
载入rvm:
source ~/.rvm/scripts/rvm
查看rvm是否安装正确:
rvm -v
结果:
rvm 1.29.9-next (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
查看已安装ruby:
rvm list
结果:
ruby-2.5.1 [ missing bin/ruby ]
ruby-2.6.0 [ x86_64 ]
=* ruby-2.6.3 [ x86_64 ]
# => - current
# =* - current && default
# * - default
卸载旧版本:
rvm remove 1.9.2
查看已知ruby版本:
rvm list known
结果:
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]
[ruby-]2.7[.0-preview1]
ruby-head
选择一个版本来安装:
rvm install 2.6.3
设置刚刚安装的版本为默认版本:
rvm 2.6.3 --default
查看ruby是否安装正确:
ruby -v
结果:
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
查看gem镜像:
gem sources -l
替换gem国内镜像:
gem source -r https://rubygems.org/
gem source -a https://gems.ruby-china.com/
查看是否替换成功:
gem sources -l
结果:
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
安装cocoapods:
sudo gem install cocoapods
这里成功之后不要急着执行pod setup,cocoapods这个项目比较大,从github上clone这个会很慢,这里直接使用国内的镜像作为master
替换cocoapods国内镜像:
cd ~/.cocoapods/repos
pod repo remove master
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
进入自己的工程,在自己工程的podFile第一行加上:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
执行pod install:
pod install
这时候pod install执行之后,就是走的ss的代理,速度还蛮快的
中间经历过重装homebrew:
https://juejin.im/post/5c738bacf265da2deb6aaf97
重装cocoapods:
https://mirror.tuna.tsinghua.edu.cn/help/CocoaPods/
git clone 很慢:
https://www.zhihu.com/question/27159393
感谢各位大佬!
2020-03-05 15:37:18 更新:
之前的梯子不好用了,更换了clashX这个工具,每次 pod install 之前向命令行添加代理就醒了,不用使用全局代理了,全局代理使用起来会有很多问题,梯子挂了,整个github就无法访问了。