Cocoapods私有库搭建

最近在整理组件化相关的东西,其中有一项就是用pod管理内部的一些公共组件,为了加深印象,下面把具体步骤记录一下(注:下面所有的内容都是基于gitlab):


1,创建一个Group,用户管理所有的代码仓库和版本仓库,如iOSPods;

2,在iOSPods下创建一个版本仓库,用来存放所有的描述文件(.podspec);

创建好后,记录仓库地址,如git@gitlab.xxx.cn:iOSPods/iOSSpecs.git

3,将版本仓库添加到本地:

pod repo add iOSSpecs git@gitlab.xxx.cn:iOSPods/iOSSpecs.git

这个时候执行`ls ~/.cocoapods/repos/`,将会发现多了一个iOSSpecs目录;

4,在iOSPods下建立代码仓库,这个代码仓库是存放真正的源码的,例如,建立一个名字为MyButton的仓库,地址为:git@gitlab.xxx.cn:iOSPods/MyButton.git

5,将MyButton仓库clone到本地任意目录:

git clone git@gitlab.xxx.cn:iOSPods/MyButton.git

6,将MyButton组件代码拷贝到MyButton本地仓库,并上传

git add .

git commit -m "original commit"

git push -u origin master

7,创建空白描述文件MyButton.podspec:

pod spec create MyButton

由于通过`pod spec create`命令创建的podspec文件含有很多注释及无用信息,简单起见,可以直接copy下面的模板替换MyButton.podspec文件的内容:

Pod::Spec.new do |s|

  s.name        = "MyButton" # 项目名称

  s.version      = "0.0.1"        # 版本号 与 你仓库的 标签号 对应

  s.license      = "MIT"          # 开源证书

  s.summary      = "Util Addtions" # 项目简介

  s.homepage    = "http://gitlab.xxx.cn/iOSPods/MyButton" # 仓库的主页

  s.source      = { :git => "git@gitlab.xxx.cn:iOSPods/MyButton.git", :tag => "#{s.version}" }#你的仓库地址,不能用SSH地址

  s.source_files = "MyButton/*.{h,m}" # 你代码的位置, MyButton/*.{h,m} 表示 MyButton 文件夹下所有的.h和.m文件

  s.requires_arc = true # 是否启用ARC

  s.platform    = :ios, "8.0" #平台及支持的最低版本

  # s.frameworks  = "UIKit", "Foundation" #支持的框架

  # s.dependency  = "AFNetworking" # 依赖库


  # User

  s.author            = { "yb_cherry" => "yb_cherry@163.com" } # 作者信息

  s.social_media_url  = "https://www.xxx.com" # 个人主页

end

8,验证描述文件是否正确:

pod lib lint 

如果出现下面的信息,说明验证通过

-> MyButton (0.0.1)

    - WARN  | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.

MyButton passed validation.

如果出现错误,可以在`pod lib lint`后面指定--allow-warnings或者--private选项

9,确认MyButton.podspec有效后,将其推送到代码库

git add MyButton.podspec

git commit -m "add podspec"

git push -u origin master

10,打标签并推送到代码库

git add -a 0.0.1 -m "0.0.1"

git push origin 0.0.1

11,将描述文件推送到版本仓库中

pod repo push iOSSpecs MyButton.podspec

注:如果在验证描述文件的正确性时使用了--allow-warnings或者--private,这个时候也需要加上同样的选项

这个命令最终执行了如下操作:

1)验证MyButton.podspec文件;

2)更新本地iOSPods版本仓库;

3)将MyButton.podspec添加到iOSPods本地仓库;

4)将MyButton.podspec推送到远端版本仓库;


以上就是搭建Cocoapods私有库的完整步骤,没有遗漏任何细节,如果遇到任何问题,可以在后面留言!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。