Pod Install又失败了么?---- 理解Pod Install流程,玩儿转Pod,我有我的任性~

1、Pod Install…… CDN:trunk Repo update failed

Cocoa Pod 是玩 iOS 的童鞋必不可少的小伙伴,是一款优秀的包管理工具。然鹅,出于各种各样的原因,pod install 失败屡见不鲜。比如笔者最近更新 cocoaPod 之后,就遇到了下面的问题:

[!] CDN: trunk Repo update failed - 2 error(s):
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/9/b/9/aubio-iOS-SDK/0.4.1/aubio-iOS-SDK.podspec.json Response: Couldn't connect to server
CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/9/b/9/aubio-iOS-SDK/0.4.4/aubio-iOS-SDK.podspec.json Response: Couldn't connect to server

“CDN: trunk Repo update failed” 为关键词搜索,发现遇到问题的小伙伴还真不少

问题热度相当高

好在,解决方案并不复杂,即:在 PodFile 中添加下面的配置(指定 Repo 源)。

source 'https://github.com/CocoaPods/Specs.git'
问题解决方案

然,问题的莫名解决并不能让一个负责人的小伙伴感到舒心……

2、搞清原理才能感到舒心

小伙伴们会有各种各样的不安,比如:
1)source 是要干嘛?
2)为什么要配置 https://github.com/CocoaPods/Specs.git 这么定制化的链接?
3)这样修改 Podfile 会留下隐坑么?
4)为什么这行配置能解决问题?

所以,为了舒心,我们需要知道……

2.1、Pod Install做了一些什么

1)找寻Repo
pod 中的 Repo,我们可以理解为 Podspec 文件的管理仓库.

What's PodSpec
A specification describes a version of Pod library. It includes details about where the source should be fetched from, what files to use, the build settings to apply, and other general metadata such as its name, version, and description.

2)寻找模块描述(Podspec)
比如我们再 Podfile 中配置了要加载 Masonry

pod 'Masonry', '1.1.0'

那么,执行 pod install 的时候,pod 会从配置的 Repo 中去寻找 Masonry 对应的 Podspec 文件。

What's Podfile
The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects.

3)找到第三方库工程,下载代码
Podspec 中包含了第三方库的工程位置信息、有效代码信息等。所以,依据找到的 Podspec 文件的描述,pod 就可以将第三方库集成进你的工程啦~

2.2、CDN问题发生在Setp 1

容易发现(别问我为什么容易……),我们片头提到的 CDN 问题的本质是 Pod Repo 关联的失败。具体来说,老版本的 cocoaPod 的默认 Repo 即:https://github.com/CocoaPods/Specs.git;而新版本 cocoaPod 的默认管理仓库切换到了 trunk(Type:CDN,URL:https://cdn.cocoapods.org/)

通过 pod repo list 命令可以很方便地查看已经配置的 Repo

本地Repo

无论是因为国内被墙还是服务器本身出现问题等任何原因啦,反正目前看来,国内小伙伴该没人能有效使用 trunk 这个 Repo,所以我们在 PodFile 中将指定 Repo 为之前的默认 Repo
即:

source 'https://github.com/CocoaPods/Specs.git'

现在舒心了嘛:

1)source是要干嘛?
A:source 是指定 Podspec 文件的查找源(指定目标Repo

2)为什么要配置 https://github.com/CocoaPods/Specs.git 这么定制化的链接?
A:参数 https://github.com/CocoaPods/Specs.gitcocoaPod 旧版本的默认 source

3)这样修改Podfile会留下隐坑么?
A:仅仅显性配置了 source 而已,当然没啥隐坑。

4)为么什么这行配置能解决问题?
A:因为Ta正中我们的痛点,让我们找到一个有效的官方Repo

然而,费心了解的底层原理,总有一些 「自己的任性」 想要实践~

3、任性:不信任官方Repo,我要我自己的Repo

木问题!

Repo 不过是一个 Podspec 的管理仓库,能找到对应的 Podspec 就好了,谁说一定要用官方的 Repo 呢?所以,我们可以建立自己的 Repo,甚至是不公开的 Repo,即 Pod 私有仓库的概念。

What's Private Pods
CocoaPods is a great tool not only for adding open source code to your project, but also for sharing components across projects. You can use a private Spec Repo to do this.

操作也很简单(当然看上面的官方介绍也行咯)
1)建立一个自己的 Podspec 管理仓库(就是一个 Git Repo
2)通过 Pod 命令,或者依照 Pod 的约定,将对应 Podspec 文件提交到第一步建立的 Repo 中。
3)本地 Pod 关联我们自己的 Repo(通过 pod repo add 命令)

# pod repo add 示例
pod repo add CYSpec https://github.com/chrisYooh/CYSpec.git

# 成功后pod repo list 应该可以看到新添加的repo信息
pod repo list
...
CYSpec
- Type: git (master)
- URL:  https://github.com/chrisYooh/CYSpec.git
- Path: /Users/chris/.cocoapods/repos/CYSpec
...

4)配置私有 Repo 源(在 Podfile 中)

source "https://github.com/chrisYooh/CYSpec.git"

理清了原理……有没有发现

一切都那样得理所当然!然而……

4、任性升级:Repo我都懒得配!

可以!

目标是获得对应模块的 Podspec 嘛!我已经知道Ta在哪啦!Repo 请靠边站!

1)直接指定第三方库的 Git工程 地址&提交号

pod 'CYNetworking', :git => 'https://github.com/chrisYooh/CYNetworking.git', :commit => '96609df'

(不成功?Baby,先保证对应Git的提交版本的工程根目录下有一个Podspec文件吧~)

5、终极任性:网络我都懒得连!

好……同意……!

比如阿里的前向推理框架MNN,在Ta的示例Demo中,Pod就直接从本地去拉……

pod 'MNN', :path => "../../"

结论

我懂原理我任性,呃……就是这样!

你可能感兴趣的:(Pod Install又失败了么?---- 理解Pod Install流程,玩儿转Pod,我有我的任性~)