Pod私有库组成:
1.Spec(存放私有库 .podspec 的Git仓库 + 本地 Pod repo )
2.构建的Pod项目(存放本地Pod项目的Git仓库 + 本地Pod项目(内部包含自己写的私有库))
一.Spec 准备工作
1.在Gitlib创建一个私有仓库, 例如:xxxSpec (本文用 "JYUtilitiesSpec" ,自己替换)
注意:要创建 README.md
2.克隆远端索引库到本地 pod repo
pod repo add JYUtilitiesSpec git@gitlab.jiayuan-inc.com:iOS/JYUtilities.git
在终端输入 pod repo list 可以看到 JYUtilitiesSpec
二.创建私有库
(1)新建Git仓库用来存放自己的本地Pod项目代码
(2)本地Pod项目用来配置自己写的私有库,包括 存储私有库代码、编辑 .podspec、编写示例代码
1.在Gitlib上创建空白私有仓库 注意:要勾选 README.md
2.创建本地Pod项目
2.1 终端输入:
pod lib create JYUtilities
按自己需要回答终端显示的问题 这里有个问题是 是否需要个示例项目,最好回答 yes
结束后显示如下目录结构
2.2 进入 GGTestTool - Example 文件夹打开项目这是个自动生成的示例项目
2.3 在 GGTestTool - GGTestTool - Classes 文件夹删除 Replaceme.h,并且将自己的代码放入此文件夹,并将文件导入 Xcode
2.4 示例项目更新 pod 如果不需要写什么示例代码则忽略
pod install
2.5 这时可以在 Example 项目中写一点示例代码做测试
2.5 在示例项目中修改 .podspec 注意下这里的 version 号,后面会用
.podspec介绍
s.dependency 一些依赖的三方
3.提交Pod项目
终端操作:
注意:1.一定要打 tag 2.打 tag 时一定要与 .podspec 里的 version 一致
git remote add origin git@gitlab.jiayuan-inc.com:iOS/JYUtilities.git
git pull origin master --allow-unrelated-histories //把远程仓库和本地同
git add .
git commit -m "初始化"
git push origin master
git tag -a 0.1.0 -m "0.1.0版本描述"
git push --tags
git tag -d 1.0.0 # 删除 tag 本地标签
git push origin :refs/tags/1.0.0 # 删除远程端指定 tag 标签
4.校验Pod项目
- ## pod lib lint 从本地验证 pod 能否通过验证
- ## pod spec lint 从本地和远程端验证 pod 能否通过验证
- ## pod spec lint --verbose 详细编译验证 podspec 合法性
- ## --allow-warnings 带有警告需要的语法
- ## --use-libraries 依赖三方库需要的语法(比如:s.dependency 'MBProgressHUD', '1.1.0')
-
-
- ## 从本地验证 pod 能否通过验证
- pod lib lint JYUtilities.podspec
- ## 从本地验证依赖三方库的 pod 能否通过验证
- pod lib lint JYUtilities.podspec --use-libraries
- ## 从本地验证带有警告的 pod 能否通过验证
- pod lib lint JYUtilities.podspec --allow-warnings
- ## 从本地验证依赖三方库且有警告的 pod 能否通过验证
- pod lib lint JYUtilities.podspec --use-libraries --allow-warnings
-
-
- ## 从本地和远程端验证 pod 能否通过验证
- pod spec lint JYUtilities.podspec
- ## 从本地和远程端验证依赖三方库的 pod 能否通过验证
- pod spec lint JYUtilities.podspec --use-libraries
- ## 从本地验和远程端证带有警告的 pod 能否通过验证
- pod spec lint JYUtilities.podspec --allow-warnings
- ## 从本地和远程端验证依赖三方库且有警告的 pod 能否通过验证
- pod spec lint JYUtilities.podspec --use-libraries --allow-warnings
-
-
- ## 详细编译验证 podspec 合法性
- pod spec lint --verbose
5.Pod 推送 .podspec
pod repo push JYUtilitiesSpec JYUtilities.podspec #后面加上一步后面的,要一致
6.验证成功后,将库文件推送到 cocoapods 服务器
此处如果没有绑定过 cocoapods 账户的情况下,此处会优先注册或绑定 cocoapods 账户
## 检测是否绑定 cocoapods 账户
## 注册 cocoapods 账户(需要在邮箱激活)
pod trunk register 邮箱地址 '用户名' —description='描述信息'
## 检测是否注册成功
pod trunk me
## 绑定 cocoapods 账户
pod trunk register 邮箱地址 '用户名'
## 将库文件推送到 cocoapods 远程端
## 将库文件推送到 cocoapods 远程端
pod trunk push JYUtilities.podspec
## 将带有警告的库文件推送到 cocoapods 远程端
pod trunk push JYUtilities.podspec --allow-warnings
## 将依赖三方库的库文件推送到 cocoapods 远程端
pod trunk push JYUtilities.podspec --use-libraries
## 将依赖三方库且带有警告的库文件推送到 cocoapods 远程端
pod trunk push JYUtilities.podspec --use-libraries --allow-warnings
## 刷新库文件,可保证通过 pod search 立即搜索的到
pod repo update
如果报错:# CDN: trunk Repo update failed错误解决
pod repo remove trunk
三.使用
1.建个 Demo
2.编辑 podfile
2.1 顶部添加 source
source 'git@gitlab.jiayuan-inc.com:iOS/JYUtilitiesSpec.git'
2.2 target 中添加自己的私有库
pod 'JYUtilities'
2.3 install
**
pod install
`注意:如果报错:Unable to find a specification for “”重启一下
pod setup
注意:
公司其他成员使用需要先
**
pod repo add JYUtilitiesSpec git@gitlab.jiayuan-inc.com:iOS/JYUtilitiesSpec.git
四.更新私有库
1.修改 Pod 项目:
- 修改Pod项目代码
- 修改 .podspec 里的 version
- 提交Pod项目代码
不要忘了打tag,与 .podspec 的 version 一致
2.更新 repo
pod repo push JYUtilitiesSpec JYUtilities.podspec #后面加上验证步骤后面的,要一致
原文地址:www.jianshu.com/p/829a68778…
原作者首页:xiaozhuanlan.com/topic/71809…