使用Cocoapods创建私有库的流程

在公司开发Framework,记录一下关于cocoapods制作私有库的过程:

1、创建私有repo仓库,比如我的是 https://gitee.com/lishengpei/lspcustom-basic-repo.git,并初始化(设置开发语言,以及readMe)

pod repo add LSPCustomBaseKit https://gitee.com/lishengpei/lspcustom-basic-repo.git

这条指令:会在~/.cocoapods/repos目录下看到 LSPCustomBaseKit 文件夹了,第一步完成,这一步通常只需要执行一次。(这个命名没有过多要求)

  

2、创建Pod项目的文件

首先cd到你想创建项目的文件夹执行如下操作,记住一定要创建一个单独的名字,否则以后pod search <私有库> 会找到Github上跟你重名的项目

pod lib create LSPCustomRepo
这条指令:会在本地创建一个workspace工程,终端中输入你的开发语言比如: ObjC,是否需要测试demo,Yes即可。其他选None, 可根据自己需要。然后自动打开创建的工程。
接下来就是在你的LSPCustomRepo 文件夹下添加自己的内容,将自己的组件代码部分放在 LSPCustomRepo/Classes下。

 2.1  同样需要在远端创建一个仓库,仓库名称和pod项目仓库名称相同,比如 https://gitee.com/lishengpei/LSPCustomRepo.git,然后将本地的pod工程push到这个远程仓库上,具体操作如下:

git add .
git commit -m "init library"
git remote 查询远程仓库是否存在,下面添加一个远程仓库。 git remote add origin https://gitee.com/lishengpei/LSPCustomRepo.git git push origin master

 2.2 如果远程仓库已经存在,需要拉下代码

git pull origin master --allow-unrelated-histories

如果有冲突,就解决下冲突, 解决之后,push代码。

3, 因为podspec文件获取版本控制的项目需要tag号,所以还要打上一个tag, 给本次提交打上tag 

git tag -a 1.0.0 -m "1.0.0"
git push --tags     #推送tag到远端仓库

4, 做完这些之后开始编辑podspec文件,填上对应的信息。

  s.source     s.description    s.version 根据项目结构,填上适当的内容

5, 本地测试podspec文件

自己可以创建一个新项目,在Podfile中指定自己编辑好的podspec文件,如下:(两种方式填写一种就行)

pod 'LSPCustomRepo', :path => '~/Desktop/LSPCustomRepo'      # 指定路径
# pod 'LSPCustomRepo', :podspec => '~/Desktop/LSPCustomRepo/LSPCustomRepo.podspec'  # 指定podspec文件

然后执行pod install命令安装,然后打开项目发现库文件已经被加载到Pods子项目中了,不过没有在Pods目录下,而是在Development Pods/LSPCustomRepo 目录下,因为是本地测试项目,没有吧podspec文件添加到Spec Repo中的缘故

确认无误后,就可以提交podspec到Spec Repo中了, 提交很简单,只需要一个命令:

pod repo push LSPCustomBaseKit LSPCustomRepo.podspec --use-libraries --allow-warnings
#前面是本地Repo名字 后面是podspec名字

没有错误之后,就可以在~/.cocoapods/repos/LSPCustomBaseKit 目录下看到自己的私有库了,同时我们远程的Spec Repo也有一次提交,已经被自动push上去了。

可以用 pod search LSPCustomRepo  查看自己的库了, 如果搜不到,那么删除缓存:~/Library/Caches/CocoaPods/  删除该路径

至此,自己的私有库就算制作好了。

6、使用制作好的Pod

在Podfile文件中,内容如下:

source 'https://github.com/CocoaPods/Specs.git'  # 官方库
source 'https://gitee.com/lishengpei/lspcustom-base-kit.git'   # 私有库

platform :ios, '8.0'

target 'TargetName' do
pod 'AFNetworking', '~> 3.0'    
pod 'LSPCustomRepo', '1.0.0'   #自己的私有库
end

详情参考: http://blog.wtlucky.com/blog/2015/02/26/create-private-podspec/

 

posted on 2020-11-26 20:05  大圣ios博客  阅读(228)  评论(0编辑  收藏  举报