1
问题描述
CocoaPods 升级到1.11后,当pod install时,默认会从 CDN 上更新第三方库文件(https://cdn.jsdelivr.net)
但是由于地域差异、网路、墙、dns污染等各种原因,会导致pod install 执行失败,此时失败的例子可能如下:
zhangyin@zhangyindeMacBook-Air kdh_iOS % pod install
Analyzing dependencies
[!] The version of CocoaPods used to generate the lockfile (1.11.2) is higher than the version of the current executable (1.11.0). Incompatibility issues may arise.
[!] CDN: trunk Repo update failed - 28 error(s):
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.10.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.11.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.12.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.13.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.14.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.15.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.16.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.17.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.18.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.19.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.19.1/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.20.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.21.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.21.1/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.22.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.30.0.beta1/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/0.30.0.beta2/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/3.0.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/3.0.1/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/3.0.2/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/3.1.2/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/3.2.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/4.0.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/4.0.1/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/4.2.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/5.0.0/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/5.0.1/SnapKit.podspec.json Response: SSL connect error
CDN: trunk URL couldn't be downloaded: https://cdn.jsdelivr.net/cocoa/Specs/1/f/6/SnapKit/5.6.0/SnapKit.podspec.json Response: SSL connect error
2
解决思路
CDN无法使用,这个是外部原因,如果有VPN可以试试,但是VPN并不总是有效,毕竟VPN还是架构在你本地的基础网络环境之上。
从CocoaPod 1.8.0开始,系统默认通过CDN 的方式来pod install,目前最新的版本是1.11.3。
先看下故障现场的情况:
通过pod repo list 可以看到当前的pod 索引库:
zhangyin@zhangyindeMacBook-Air kdh_iOS % pod repo
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/zhangyin/.cocoapods/repos/trunk
此时,新安装好的CocoaPods 1.11.0 版本的Pod索引库的Type是CDN方式的,执行pod install 就会默认走trunk这个索引库。
但是因为网络问题,此路不通,那么就换一条路:更换Pod索引库。
3
解决方案:强制Pod install时采用自定义的Pod索引库
第1步:添加新的Pod索引库的源:
姿势1:添加 官方 CocoaPods Git 源
执行 pod repo add cocoapods https://github.com/CocoaPods/Specs.git
说明:
既然CDN都无法使用,官方的pod repo的源大概率也不太好使,可以多试几次,实在不行就不要用官方的源了;
下面这个例子就是添加官方源失败的现场:
现场报出各种稀奇古怪的错误,此时不要恋战,赶紧换姿势;
zhangyin@zhangyindeMacBook-Air kdh_iOS % pod repo add cocoapods https://github.com/CocoaPods/Specs.git
Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git -- cocoapods
Cloning into 'cocoapods'...
error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly before end of the underlying stream
error: 6614 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
姿势2:添加自定义Pod 索引库的源
添加大名鼎鼎的 清华 CocoaPods 镜像源
执行pod repo add tuna https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
zhangyin@zhangyindeMacBook-Air local % pod repo add tuna https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
Cloning spec repo `tuna` from `https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git`
速度还不错,添加好后执行pod repo list看看效果:
zhangyin@zhangyindeMacBook-Air local % pod repo list
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/zhangyin/.cocoapods/repos/trunk
tuna
- Type: git (remotes/origin/master)
- URL: https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
- Path: /Users/zhangyin/.cocoapods/repos/tuna
2 repos
多了一个:名叫‘tuna’的Pod 源,Type为git方式;
第2步:更新本地的Pod 索引库的缓存信息
执行 pod repo update --verbose
zhangyin@zhangyindeMacBook-Air kdh_iOS % pod repo update --verbose
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update
Updating spec repo `trunk`
CDN: trunk Relative path downloaded: deprecated_podspecs.txt, save ETag: W/"6287c3f3-940fe"
CDN: trunk Going to update 3 files
CDN: trunk Relative path: CocoaPods-version.yml, has ETag? "6287b0a4-38"
CDN: trunk Relative path: all_pods_versions_1_f_6.txt, has ETag? W/"6287bdf6-472"
CDN: trunk Relative path: all_pods_versions_f_4_e.txt, has ETag? W/"6287b0a4-50b"
CDN: trunk Relative path downloaded: CocoaPods-version.yml, save ETag: "6287c8ad-38"
CDN: trunk Relative path downloaded: all_pods_versions_1_f_6.txt, save ETag: W/"6287c8ad-472"
CDN: trunk Relative path downloaded: all_pods_versions_f_4_e.txt, save ETag: W/"6287c8ad-50b"
CocoaPods 1.11.3 is available.
To update use: `sudo gem install cocoapods`
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.11.3
Updating spec repo `tuna`
$ /usr/bin/git -C /Users/zhangyin/.cocoapods/repos/tuna fetch origin --progress
$ /usr/bin/git -C /Users/zhangyin/.cocoapods/repos/tuna rev-parse --abbrev-ref HEAD
master
$ /usr/bin/git -C /Users/zhangyin/.cocoapods/repos/tuna reset --hard origin/master
HEAD is now at ef488a02bffb [Add] QiscusMultichannelWidget 2.0.4-beta.2
至此,添加新的Pod索引库完成
第3步:
在自己项目的Podfile文件的第一行中,添加声明,告诉系统pod install时需使用自定义的Pod索引库,例如:(本例中使用的是清华的源)
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
target 'MyProject' do
use_frameworks!
end
如果一切顺利,此时就可以愉快的执行 pod install 操作了,例如:
zhangyin@zhangyindeMacBook-Air kdh_iOS % pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There are 31 dependencies from the Podfile and 35 total pods installed.
[!] Unable to read the license file `FILE_LICENSE` for the spec `YXAlog_iOS (1.0.6)`
[!] Unable to read the license file `FILE_LICENSE` for the spec `YXAlog_iOS (1.0.6)`
[!] Unable to read the license file `FILE_LICENSE` for the spec `YXAlog_iOS (1.0.6)`
[!] Unable to read the license file `FILE_LICENSE` for the spec `YXAlog_iOS (1.0.6)`
[!] The `kdh [Debug]` target overrides the `EXCLUDED_ARCHS[sdk=iphonesimulator*]` build setting defined in `Pods/Target Support Files/Pods-kdh/Pods-kdh.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `kdhUITests [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-kdh-kdhUITests/Pods-kdh-kdhUITests.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `kdhUITests [Release]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-kdh-kdhUITests/Pods-kdh-kdhUITests.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `kdhUITests [AdHoc]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-kdh-kdhUITests/Pods-kdh-kdhUITests.adhoc.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.
4
番外篇
flutter项目中 .ios 目录下的Podfile文件中的第一行也需要添加使用自定义Pod索引库的的声明语句,这样在vscode中使用iOS模拟器运行flutter项目时,pod install才可以正确运行,例如:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoadPods/Specs.git'
target 'MyProject' do
use_frameworks!
end