iOS 创建组件库

索引库 repo

索引文件(.podspec文件)

1.搭建私有库之前必须要先创建索引库

1)首先检查当前电脑的索引库

pod repo

2)在gitlab上创建一个新的库,这个库用来保存私有库的podspec文件,所以我们一般起名字最好是 xxxSpec用以区分这个库的作用。

3) 创建本地索引库,然后将其于刚才创建的远程索引库相关联,注意!!!此时的远程索引库是空的!空的!空的!但是必须得有master分支,所以你可以添加一个readme文件。

两种方式:01-https方式;02-ssh方式(ssh方式需提前配置SSH

pod repo add 本地索引库名称 远程索引库的git地址

例如:pod repo add PinnetSpec http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSpec.git

4) 检查是否安装成功

cd 到新建索引库

cd ~/.cocoapods/repos/PinnetSpec 

验证索引文件仓库

pod repo lint .

删除本地repo

pod repo remove [索引库名称]

更新本地的Pod 索引库的缓存信息

pod repo update --verbose

2.创建本地私有库(组件库)

1)创建本地私有库

cd到将要创建的本地私有库文件夹下执行

pod lib create [组件库名称] 

这里组件库名称一定要与远程仓库创建的名称一致

例如: pod lib create PinnetHeaderSegment

报错[!] /usr/bin/git clone https://github.com/CocoaPods/pod-template.git xxx

Cloning into 'xxx'...

fatal: unable to access 'https://github.com/CocoaPods/pod-template.git/': error:02FFF036:system library:func(4095):Connection reset by peer

或者

fatal: unable to access 'https://github.com/CocoaPods/pod-template.git/': SSL certificate problem: unable to get local issuer certificate

去除代理

git config --global http.proxy

git config --global --unset http.proxy

2)参照下图进行参数配置

​​​​​​​

3)配置完成后会自动打开一个HeaderSegmentView-Example项目,层级如下图

4)将Classes文件夹下面的ReplaceMe.m文件删除掉,替换成组件库的代码

5)安装pod库

cd到Example文件夹下执行

pod install

等待一段时间

6)修改xxx.podspec配置文件

Ps:

(A)s.homepage需要修改为远程私有库首页地址, 不是私有索引库的地址!!!

(B)s.source 需要修改为远程私有库的git地址(选择使用HTTPS地址)!!!

(C)s.version 私有库版本号一般改为1.0.0

3.上传本地私有库

1)在gitlab上创建远程私有库。注意!!!这个库是存远程私有库代码的,不要跟远程索引库混淆啦!!!

git remote add origin 远程仓库地址 ##未关联地址时,需要添加关联远程仓库地址

2)将本地私有库推送到远程私有库

cd到本地私有库文件夹PinnetHeaderSegment下执行

构建本地git代码库

git init

git status ##查看上次提交后是否对文件再做了修改红色文件表示没有更新到缓存中

将红色文件更新到缓存中

git add 文件名 ##上传单个文件 

git add .  ##上传所有文件

git status ##更新成功文件变成绿色

进行文件提交

git commit -m ‘提交信息’ 

④先拉取远程代码

git pull origin master 

或者git branch --set-upstream-to=origin/master master

报错“fatal: refusing to merge unrelated histories”(即,不知道彼此的存在,并已不匹配的项目提交历史)可执行git pull origin master --allow-unrelated-histories 

之后上面的命令可能会进入vi模式,按提示输入更新信息后,按【ESC】键跳到命令模式,按下冒号按键,然后再按下【wq】,即可保存退出vi的编辑状态,

报错fatal: couldn't find remote ref master

这个仓库还没有文件,空的,直接push本地修改就可以了,不需要pull了

报错 fatal: 'origin' does not appear to be a git repository

fatal: Could not read from remote repository.

重新cd文件夹位置

git remote add origin 远程仓库地址 #关联远程仓库地址​​​​​​​

提交本地缓存到远程代码库

提交修改前,再次确认不修改后,修改spec文件中的tag值后,再之后push

git push -u origin master 

推送版本到master分支(-f强制推送,覆盖掉之前的所有文件)

git push origin master -f

4.进行本地校验

初始命令

pod lib lint --verbose --allow-warnings

如果依赖了其他的第三方库

pod lib lint --verbose --allow-warnings --sources="cocoapods库地址,私有库远程地址"

如果其他第三方私有库又依赖了其他的库,需增加--use-libraries

pod lib lint --verbose --use-libraries --allow-warnings --sources="cocoapods库地址,私有库远程地址"

显示xxx passed validation.表示校验通过

Ps:

--verbose:有些非语法错误是不会给出错误原因的,这个时候可以使用来查看详细的验证过程来帮助定位错误。
--allow-warnings:表示允许警告。
--use-libraries:表示使用静态库或者是framework,这里主要是解决当我们依赖一些framework库后校验提示找不到库的时候用到。

--sources=‘master,privateSpecs':指定源,比如你的私有pod同时依赖了公有库和私有库,你必须指定源才行,因为默认只会去在公有源中查找对应的依赖

报错[!] xxx did not pass validation, due to 1 error.

需要解决Example工程中的所有报错后重新提交

ERROR | [iOS] unknown: Encountered an unknown error (CDN: trunk URL couldn't be downloaded: https://cdn.cocoapods.org/all_pods_versions_a_1_5.txt Response: SSL peer certificate or SSH remote key was not OK) during validation.

执行pod repo remove trunk 删除下面的repo源

trunk

- Type: CDN

- URL:  https://cdn.cocoapods.org/

- Path: /Users/xxx/.cocoapods/repos/trunk

报错ERROR | [iOS] unknown: Encountered an unknown error (Unable to find a specification for `PinnetBase` depended upon by `PinnetHeaderSegment`

或报错

[!] Couldn't determine repo type for URL: `https://xxx/`: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (unable to get local issuer certificate)

或报错[!]Found multiple specifications for ‘xxx’

未引用github第三方库执行

pod lib lint --verbose --use-libraries --allow-warnings --sources='http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSpec.git'

有引用github第三方库执行

pod lib lint --verbose --use-libraries --allow-warnings --sources='https://github.com/CocoaPods/Specs.git,http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSpec.git'

5.打Tag

tag必须与spec文件里面写的版本号要一致,要一致,要一致!!!后期版本修改了任何东西都需要重新打tag

git tag 版本号(要跟spec文件里面写的版本号一致)

git push origin --tags

6.远程校验

1)tag打上去之后,进行远程校验,其实和本地校验一样,本地如何校验通过的,远程只需要把lib字段改成spec就可以了,例如我的

pod spec lint --verbose --allow-warnings

如果依赖了其他的第三方库

pod spec lint --verbose --allow-warnings --sources="cocoapods库地址,私有库远程地址"

如果其他第三方私有库又依赖了其他的库,需增加--use-libraries

pod spec lint --verbose --use-libraries --allow-warnings --sources="cocoapods库地址,私有库远程地址"

未引用github第三方库执行

pod spec lint --verbose --use-libraries --allow-warnings --sources='http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSpec.git'

有引用github第三方库执行

pod spec lint --verbose --use-libraries --allow-warnings --sources='https://github.com/CocoaPods/Specs.git,http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSpec.git'

报错- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSearchBar.git /var/folders/sn/56pkr11n0vv91b5q37mjgxf80000gn/T/d20221021-1427-1o5usog --template= --single-branch --depth 1 --branch 1.0.0

Cloning into '/var/folders/sn/56pkr11n0vv91b5q37mjgxf80000gn/T/d20221021-1427-1o5usog'...

warning: Could not find remote branch 1.0.0 to clone.

fatal: Remote branch 1.0.0 not found in upstream origin

警告:找不到要克隆的远程分支1.0.0。

致命:在上游源中找不到远程分支1.0.0

gitlab上查看组件库tag

 先去打tag

7.提交podspec文件到最开始创建的私有索引库PinnetSpec

1)所有验证通过之后,要将spec文件推送到最开始创建的远程索引库当中

如果报错

[!] Unable to find the `PinnetSpec` repo. If it has not yet been cloned, add it via `pod repo add`.

1、添加源地址

pod repo add PinnetSpec http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSpec.git

2、将spec推送到远程

pod repo push [索引库名称] [组件库名称].podspec

pod repo push PinnetSpec PinnetBase.podspec --allow-warnings --use-libraries --verbose

报错[!] Couldn't determine repo type for URL: `https://cdn.cocoapods.org/`: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (unable to get local issuer certificate)

先切外网执行一遍,再切内网执行一遍

报错The xx.podspec specification does not validate.

命令添加后缀--allow-warnings --use-libraries --verbose

2)最后推送上去之后,在本地的索引库中的样子如下图

3)这个时候验证一下你的私有库

先更新一下pod库,不然找不到你刚上传的私有库

pod repo update -- 

pod search 私有库名称

使用私有库

在Example文件夹的Podfile文件里

1、添加source源路径

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

source 'http://code.pinnettech.cn/pinnet/IESP880/IOS/PinnetSpec.git'

2、pod ‘PinnetBase’

更新远程私有库(组件库)

1、修改xxx/xxx/Classes文件夹下对应的库文件

2、更新测试工程的pod库文件

pod update --no-repo-update

3、更新xxx.podspec文件的配置信息,版本号tag一定要改

4、提交代码到远程仓库

git push orgin master

5、更新tag标签

git tag x.x.x

git push --tags

6、验证私有库

pod lib lint --private

pod spec lint

7.更新远程和本地的私有索引库

pod repo push [索引库名称] [组件库名称].podspec

私有库图片资源处理

·  把自己的图片资源直接复制到桌面xxKit/xxKit/Assets 文件夹内( Assets 是专门用来存放组件图片资源 )

·  cd到桌面组件xxKit的Example目录下
cd xxx/Example
pod install
​​​​​​​

猜你喜欢

转载自blog.csdn.net/baidu_33298752/article/details/130946655