美文网首页
iOS-私有 CocoaPods库

iOS-私有 CocoaPods库

作者: malgee | 来源:发表于2018-12-05 15:38 被阅读20次

1. code repository是代码仓库,我们把包代码上传到这个仓库。

2. spec repository是配置仓库,所有的配置按照包名、版本号分门别类的存放在这个仓库。这个仓库只用来存放spec文件,不存放代码。

制作私有 CocoaPods库大致需要两大步操作:

第一步:code repository 代码库

  • 首先需要在gitlab上创建需要发布的私有代码库
  • clone仓库到本地(我这里演示的克隆到桌面)
$ git clone http://git.xxxxxxx.com/maling/MGtest.git

完成之后你会发现 MGtest文件夹📂下是一个空的文件夹,也不完全是空的,还有一个 .git隐藏文件, 如果还是看不到 .git隐藏文件,可以用下面2行命令显示或者隐藏

//打开隐藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
//关闭隐藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false

由于MGtest文件夹📂里面是空,需要自己创建LICENSE和README.md文件,可以从其它地方拷贝进来

  • 创建 MGtest.podspec说明文件

每个 Pods 远程库必须有且仅有一个名称和远程库名保持一致,后缀名为 .podspec 的描述文件。

  1. cd到当前 MGtest 文件夹下
  2. 命令执行 $ pod spec create MGtest 就会得到 MGtest.podspec 说明文件 如下图:

其中MGtest文件就是你要发布使用的库文件内容

  1. 编辑MGtest.podspec 文件
Pod::Spec.new do |s|

s.name         = "MGtest"
s.version      = "1.0.0"
s.summary      = "The data is being tested and can be modified here."
s.homepage     = "http://xxxxxx/maling/MGtest"
s.license      = "MIT"
s.license      = { :type => "MIT", :file => "LICENSE" }
s.author       = { "maling" => "maling@amberweather.com" }
s.platform     = :ios, "9.0"
s.source       = { :git => "http://xxxxxx/maling/MGtest.git", :tag => s.version }
s.source_files  = "MGtest/*.{h,m}"
s.requires_arc = true

end
  1. 验证 MGtest.podspec 文件是否正确
$ pod lib lint

如果出现MGtest passed validation 说明验证通过,可以继续往下进行,如下图

如果有警告,会导致无法通过,需要添加--allow-warnings
如果使用了c函数相关的,静态库,需要添加--use-libraries
如果依赖了私有库,需要添加私有库源--sources='https://github.com/CocoaPods/Specs.git, https://github.com/xxxx/xxSpecs.git(私有索引库地址)

 $ pod lib lint --verbose --use-libraries --allow-warnings --sources='https://github.com/CocoaPods/Specs.git, https://github.com/xxxx/xxSpecs.git(私有索引库地址)'

pod lib lint (从本地验证你的pod能否通过验证)
pod spec lint (从本地和远程验证你的pod能否通过验证)
pod lib lint --verbose (加--verbose可以显示详细的检测过程,出错时会显示详细的错误信息)
pod lib lint --allow-warnings (允许警告,用来解决由于代码中存在警告导致不能通过校验的问题)
pod lib lint --help (查看所有可选参数,可选参数可以加多个)

$ pod lib lint --verbose --use-libraries --allow-warnings --no-clean
  1. 验证通过后,把代码提交到仓库即可, 并且设置 tag标签
$ git add .
$ git commit -m "1.0.0"

$ git tag "1.0.0"  // 设置标签
$ git push --tags

$ git push origin master  // 提交到远程服务器
$ pod spec lint --verbose --use-libraries --allow-warnings --no-clean

如果上面👆操作都没问题的话就可以看到仓库里面的内容了,如下图:

第二步: spec repository是配置仓库


MGSpecs仓库创建好之后也是一个空的仓库,主要是存放其他私有库的spec文件,就如同官方的https://github.com/CocoaPods/Specs是用来存放所有官方的specs文件一样。
  • 添加MGSpecs仓库
$ pod repo add MGSpecs http://xxxxxxxx/maling/MGSpecs.git

注意:上面的命令的解释如下:

pod repo add REPO_NAME SOURCE_URL
其中的 REPO_NAME 是我们要添加的私有repo的名称(这里填的是: MGSpecs),后面是仓库的 gitlab 地址。这里做的其实是创建的工作,也就是在~/.cocoapods/repos目录下添加了一个以你的私有MGSpecs为名的文件夹,但是并没有添加spec文件。

命令行执行前:



命令行执行后:多了一个MGSpecs的空文件夹📂


  • 将上面创建的 MGtest.podspec 命令行push操作到你的 Spec Repository

命令行:

$ pod repo push MGSpecs MGtest.podspec

这时候你会发现MGSpecs文件夹📂有内容了如下图:


这个时候执行 pod search MGtest操作就可以搜索到上面的MGtest库了

注意

点开master文件夹下面的specs目录,其下存放的就是所有提交到 CocoaPods 的开源库的 podspec 文件的集合。

  • 在项目中的Podfile中增加刚刚制作的好的Pod并使用。
source 'https://github.com/CocoaPods/Specs. git'        #官方仓库地址

source ‘http://xxxxxxxx/maling/MGSpecs.git’        #私有仓库地址

platform :ios, '8.0'
target 'MGDemo' do

pod ‘MGtest’

end


参考
创建私有 CocoaPods 仓库

相关文章

网友评论

      本文标题:iOS-私有 CocoaPods库

      本文链接:https://www.haomeiwen.com/subject/iawicqtx.html