美文网首页
cocoapods创建私有仓库

cocoapods创建私有仓库

作者: aspmcll | 来源:发表于2017-08-11 00:52 被阅读0次
利用cocoapods来创建私有仓库步骤
  • 1.创建一个管理私有仓库的容器
  • 2.制作私有仓库
  • 3.验证私有仓库并加入到第一步创建的容器中

创建私有仓库容器

为什么要创建一个私有仓库容器
打开终端进入用户目录 cd ~/.cocoapods可以寄看到以下信息

DB7EA5BD-FF41-445C-91CC-89FCD2869A30.png
进入到repos下的repos下的master再往下找,可以看到一些我们我们熟悉的东西
5637D7FC-7552-46D6-95BE-C51AE9DA890A.png
这个仓库下存储了依托在cocoapods的第三库的一个索引xxx.podspec.json(第二步所对应的json文件),cocoadpoads通过这个索引下载第三方代码
说到这里大家应该差不多明白了创建一个容器的原因了,就如官方工作原理一样,在安装cocoapods的时候,把当前依托在coocapod的第三库的一个索引文件下载到本地,以后只需要进行增量更新即可。如果每次安装第三库的时候都去远端服务器去查找podfile中的每个依赖,服务器的压力太大,客户端的速度慢。私有仓库也是同样的道理
原因说了现在来讲如何创建这个容器,很简单 --pod repo add name url
以github为例,在github上建立一个仓库 ,把url换成该仓库的地址,name换成你自己想取的名字即可,实质上就是git remote set-url 本地和远程关联起来。
pod repo add JSSpec https://github.com/jsonsnow
创建私有仓库

通过cocoapods的一个工具快速生成一些配置文件
pod lib create XXX


4E1779D1-8C80-4C2C-B0EE-E658192D1C01.png

查看生成的podspec文件

#
# Be sure to run `pod lib lint CLLTest.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = 'CLLTest'
  s.version          = '0.1.0'
  s.summary          = 'A short description of CLLTest.'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://github.com/jsonsnow/CLLTest'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'jsonsnow' => '1183010734@qq.com' }
  s.source           = { :git => 'https://github.com/jsonsnow/CLLTest.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = 'CLLTest/Classes/**/*'
  
  # s.resource_bundles = {
  #   'CLLTest' => ['CLLTest/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end

其中s.source_files = 'CLLTest/Classes/*/' ,就是pod为追踪的文件,在该目录下的文件都会随着pod的发版而发布出去,对应的Xcode位置如下图

ADF11C11-F0B4-45F3-A928-5EDA3BE873A9.png
这部分内容很多,但通过cocoapods官方模板,对于一般工程往往就可以直接进行第三部了--验证和加入到自己的创建
验证私有仓库并加入到第一步创建的容器
推送代码到远端

当我们为自己的pod添加了代码后,与一个远端地址关联起来,把本地代码推送到远端后,就可以进行验证了

git remote set origin url
git add .
git commit -m ""
git push origin master

需要注意的是pod是通过tag来管理版本的因此我们还需要为工程打上tag

git tag 0.0.1
git push origin 0.0.1

tag一般和podspec中的version一致

验证仓库

pod lib lint(需要在当前.podsepc目录下)进行本地验证
验证通过后
pod repo push xx_repo xxx.podspec,验证并发布
xx_repo:第一步创建的仓库管理容器
xxx.podspec:待发布的仓库


整个过程大致如上所述,列举一些遇到的问题
pod lib create 时候出现如下错误

lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:120:in `require': cannot load such file -- colored2 (LoadError)  

解决方法

sudo gem install colored2
sudo gem update --system

包含私有仓库的podfile文件需要加上第一步容器的地址和cocoapods的
source 'https://github/jsonsnow'
source 'https://github.com/CocoaPods/Specs.git'


pod lib lint 成功 但是pod repo push xx_repo xxx.podspec失败一般是tag混乱导致
比如有私有仓库A和B,B依赖A,A在repo中有两个tag0.0.1,和0.0.2,但A远程只有一个tag0.0.1,再验证的时候cocoapods从仓库容器得到的是0.0.2但是A的远端却找不到这个tag,因此会出错


一般我们在制作pod的时候,如果依赖本地的pod,往往会在podfile这样写

pod 'xxxx',:path => ’../xxx‘

当发版的时候需要去掉后面path部分,不然验证也不会通过,验证的时候会根据podfile文件来创建一个工程,指定path会导致依赖找不到。

相关文章

网友评论

      本文标题:cocoapods创建私有仓库

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