pod 私有库搭建

本文详细介绍了如何在Gitee上创建私有仓库来存放和管理组件,包括创建组件项目,配置podspec文件,提交到仓库,打标签,验证podspec的有效性以及组件的更新和维护过程。此外,还强调了在使用组件时需注意的事项,如正确指定组件管理仓库地址。
摘要由CSDN通过智能技术生成

一、 创建2个私有仓库

1. 在Gitee中创建组件仓库(私有)

作用:存放组件代码

https://gitee.com/yuanzhiying/information-module.git

image.png

image.png

2. 在Gitee中创建组件管理仓库(私有)

作用:管理所有组件

https://gitee.com/yuanzhiying/manager-module.git

image.png

image.png

二、远程组件管理仓库添加到本地

1. 进入本地的.cocoapods/repos目录

$ cd .cocoapods/repos

2. 将远程组件管理仓库添加到本地的仓库中

$ pod repo add ManagerModule https://gitee.com/yuanzhiying/manager-module.git

image.png

三、创建组件

1. 进入桌面目录,创建InformationModule

$ cd Desktop

$ pod lib create InformationModule

2. 根据提示进行选择:

image.png

3. 创建成功,自动打开项目。

四、配置组件项目

1. 进入项目的Example中,执行pod install

$ cd InformationModule/Example

2. 修改InformationModule.podspec如下:

image.png

3. 修改项目的Swift版本

image.png

五、提交组件项目到仓库

$ cd Desktop/InformationModule
$ git status
$ git add .
$ git commit -m '提交资讯组件'
$ git remote add origin https://gitee.com/yuanzhiying/information-module.git
$ git pull origin master --allow-unrelated-histories
...
解决LICENSE文件冲突
...
$ git status
$ git add .
$ git commit -m '解决冲突'
$ git branch --set-upstream-to=origin/master master
$ git pull
$ git push origin master

image.png

六、打tag,并提交tag到远程仓库

根据podspec中版本打tag,并提交tag到远程仓库

$ git tag -a 0.1.0
填写tag描述
$ git push --tags

七、验证podspec有效性并提交

pod lib lint和pod spec lint区别: pod lib lint = local, pod spec lint = local/remote pod lib lint: Will lint your pod locally, and will just ensure that you provided everything properly to create your pod. But it will not be enough to validate your pod, Only pod spec lint will. pod spec lint: Will lint your pod anywhere. By that I mean that you can have your pod source code up on GitHub, for example, and it will lint. If the pod spec lint returns without errors, you can push the linted pod up to Cocoapods.

1. 使用:$ pod spec lint InformationModule.podspec

$ pod spec lint InformationModule.podspec -> InformationModule (0.1.0) - WARN | url: The URL (https://gitee.com/yuanzhiying/information-module) is not reachable. - NOTE | xcodebuild: note: Using new build system - NOTE | xcodebuild: note: Building targets in parallel - NOTE | xcodebuild: note: Using codesigning identity override: - - NOTE | xcodebuild: note: Build preparation complete - NOTE | [iOS] xcodebuild: note: Planning build - NOTE | [iOS] xcodebuild: note: Analyzing workspace - NOTE | [iOS] xcodebuild: note: Constructing build description - NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App') Analyzed 1 podspec. [!] The spec did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).

https://gitee.com/yuanzhiying/information-module是私有仓库,访问不到,在命令后加上--allow-warnings

2. 使用:$ pod spec lint InformationModule.podspec --allow-warnings

复制代码

$ pod spec lint InformationModule.podspec --allow-warnings

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:229: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777 -> InformationModule (0.1.0) - WARN | url: The URL (https://gitee.com/yuanzhiying/information-module) is not reachable. - NOTE | xcodebuild: note: Using new build system - NOTE | xcodebuild: note: Building targets in parallel - NOTE | xcodebuild: note: Using codesigning identity override: - - NOTE | xcodebuild: note: Build preparation complete - NOTE | [iOS] xcodebuild: note: Planning build - NOTE | [iOS] xcodebuild: note: Analyzing workspace - NOTE | [iOS] xcodebuild: note: Constructing build description - NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App') Analyzed 1 podspec. InformationModule.podspec passed validation.

验证通过。

3. 将资讯组件提交到管理组件的本地和远程仓库中

$ pod repo push ManagerModule InformationModule.podspec

image.png

本地仓库:

image.png

远程仓库:

image.png

pods中搜索:pod search InformationModule

image.png

八、组件的更新和维护

1. 添加新的文件到Classes文件夹下,实现简单的代码,进入Example目录,执行pod install,新的文件会出现在Pods里。

image.png

image.png

2. 修改InformationModule.podspecs.version为0.1.1
3. 提交新代码到组件仓库里
$ cd Desktop/InformationModule
$ git status
$ git add .
$ git pull
$ git push
4. 打新的tag
$ git tag -a 0.1.1 
 填写tag描述 
$ git push --tags
5. 验证podspec文件

$ pod spec lint InformationModule.podspec --allow-warnings 验证通过。

6. 将资讯组件提交到管理组件的本地和远程仓库中

$ pod repo push ManagerModule InformationModule.podspec

九、组件的使用

1. 新建测试项目,并添加pods支持
2. PodFile中添加资讯组件模块
platform :ios, '9.0'
use_frameworks!

source 'https://gitee.com/yuanzhiying/manager-module.git'

target 'TestDemo' do
  pod 'InformationModule', '~> 0.1.1'
end

注意:

此处要填写的是组件管理仓库的地址,如果填错成了组件的地址,会爆出以下错误:

[!] An unexpected version directory Classes was encountered for the /Users/yuanzhiying/.cocoapods/repos/gitee-yuanzhiying-information-module/InformationModule Pod in the InformationModule repository.

3. 更新本地的仓库

$ pod repo update

4. 执行pod install,成功

image.png

5. 项目中使用

导入资讯组件,并使用

image.png

如果找不到模块或模块的方法,clean项目并Command + B编译项目.

作者:xmb
链接:https://juejin.cn/post/6989905586745786381/
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值