在组件化实施过程中,我们通常使用framework的方式来集成各个模块,
但是这种方式集成很不方便,效率不高。故采用cocopods来管理组建会
方便很多,易于集成和维护。
复制代码
一、创建私有库
1、创建命令:
pod lib create x xxx
2、回答如下问题
如果选择带有demo的,话完成后会自动打开demo工程
3、相关代码写在这里
4、编辑podspec文件
主要是填写描述、证书、组建地址
5、添加依赖
主要有三种:
自建文件夹、引入别人的代码块、引入SDK
6、验证podspec文件
pod lib lint –private
7、demo调试
写完代码,example工程pod install –no-repo-update 或者 pod install就可以
创建完私有库还不算完,我们实际开发过程中,组件化会抽出很多公用组建,
例如:网络请求、工具类、基类、路由等组建,这些组建都需要在各个模块类引用,
所以我们还要创建私有库的索引库。
复制代码
8、推送到远程仓库
二、创建私有库索引
索引库是存放spec文件的地方,用于索引到代码的位置
复制代码
1、添加索引库到本地
首页查看本地索引库列表
pod repo list
正常有2个repo:
cocoapods - Type: git (remotes/origin/master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/bhj/.cocoapods/repos/cocoapods
trunk - Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/bhj/.cocoapods/repos/trunk
复制代码
pod repo add 索引库名字 索引库git地址
例如:
pod repo add HJRepo github.com/developerBH…
添加完成之后再次执行 pod repo list就能看到私有库了:
cocoapods - Type: git (remotes/origin/master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/bhj/.cocoapods/repos/cocoapods
HJRepo
- Type: git (main)
- URL: https://github.com/developerBHJ/HJRepo.git
- Path: /Users/bhj/.cocoapods/repos/HJRepo
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/bhj/.cocoapods/repos/trunk
复制代码
2、将私有库的podspec文件添加到repo
pod repo push HJRepo HJTextView.podspec –allow-warnings
3、建立好关联后,我们就算创建成功了
使用时需要在项目中添加源
source ‘gitea.xxxx.com:xxxx/xxxx/HJSpec…‘
source ‘github.com/CocoaPods/S…‘
到这里就算全部创建完成了。
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END