iOS pod install 失败深度解决方案

由于众所周知的原因,Github 访问速度很慢,造成 pod install 执行中会遇到类似以下的报错:
[!] Error installing SobotKit [!] /usr/local/bin/git clone https://github.com/ZCSDK/SobotKit.git /var/folders/nz/zvr167xs1zx791xd4334hxnh0000gp/T/d20220304-73308-57w6i5 --template= --single-branch --depth 1 --branch 3.0.8 Cloning into '/var/folders/nz/zvr167xs1zx791xd4334hxnh0000gp/T/d20220304-73308-57w6i5'... fatal: unable to access 'https://github.com/ZCSDK/SobotKit.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443

失败原因

首先我们需要了解 pod install 的过程。
当执行 pod install 的时候,程序会从工程里找到 Podfile 定义的仓库以及地址,并且在 ~/.cocoapods/repos/master/Specs目录下新建当前仓库的 *.podspec.json 资源文件。
比如 pod install SobotKit 时,首先对 SobotKit 进行 MD5 计算获取摘要,取 MD5 的前三位 5e7 建立文件夹:~/.cocoapods/repos/master/Specs/5/e/7/Sobotkit,从该目录下找到你所需的版本,然后打开 *.podspec.json 找到 source 节点,我们可以看到 source 节点下面是 github 的地址,就是该 github 地址太慢导致的上面的错误,那么该怎么解决呢?

github 加速方案

容我先介绍一下 github 访问慢、失败的三种解决方案。

  1. 全局替换 github 域名:
  • git config --global url."https://hub.fastgit.org".insteadOf https://github.com
  • git config --global url."https://gitclone.com".insteadOf https://github.com
  • git config --global url."https://github.com.cnpmjs.org".insteadOf https://github.com
    可以挨个试试,不保证有效。
  1. 将需要的 github 仓库转换成 gitee 仓库,注册一个 gitee 账号,进入 https://gitee.com/projects/import/url ,将 github 仓库导入。git clone 的时候用 gitee 仓库替换 github 地址。

  2. 源替换方式,使用 https://github.zhlh6.cn/ 工具网站,获取加速地址。

解决方案

github 加速问题可以使用上述三种方式解决。如果第一种方案有效,pod install 即可成功执行。若第一种方案仍失败的话,可以使用第二种或者第三种方案,将 *.podspec.json 的 source 替换成第二种或者第三种生成的源。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值