组件化之私有库

此文不会对CocoaPods的安装以及基本要求作说明,要求版本在0.33或以上; 此文只是为了记录自己舒服的方式以及思维创建私有库!


  • CocoaPods trunk 是什么?什么作用?
    1. CocoaPods 是一个认证和Cocoapods API 服务
    2. 用来发布或者更新一个cocoapods 库
      pod trunk register [email] ["userName"] --description="描述"
      使用正确的email 地址注册trunk,需要点击email中的验证信息,获取认证和使用权
      pod trunk me 查看自己session信息
      pod trunk add-owner [pod库] [email]
      pod trunk push [私有库名称(或者没有则提交到cocoapod repo)] [pod 库 .specs] 或者 pod repo push [repo名] [pod库.specs]
  • 私有库创建
  1. 创建一个远程仓库存放私有库specs关联本地创建的repo
    在gitlab端创建一个私有group仓库,copy remote repo path
    terminal:pod repo add 【repo name 】【remote repo】关联本地仓库和远程仓库
  2. 创建工程
    创建一个代码远程仓库,对应本地仓库
  3. 工程目录添加.specs文件
    pod spec create [文件名] 会生成示例文件
    也可以手动创建xxx.podspec,然后添加需要的配置代码
    *( 也可以使用 pod lib create xxx 命令生成示例代码和spec文件,推荐使用这种方式很方便 )
  • 记录需要基本要添加的代码:
    简单的.podspec
Pod::Spec.new do |spec|
  spec.name         = 'Reachability'
  spec.version      = '3.1.0'
  spec.license      = { :type => 'BSD' }
  spec.homepage     = 'https://github.com/tonymillion/Reachability'
  spec.authors      = { 'Tony Million' => '[email protected]' }
  spec.summary      = 'ARC and GCD Compatible Reachability Class for iOS and OS X.'
  spec.source       = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' }
  spec.source_files = 'Reachability.{h,m}'
  spec.framework    = 'SystemConfiguration'
end

详细的spec

Pod::Spec.new do |spec|
  spec.name          = 'Reachability' # 库名
  spec.description = <<-DESC
                                      #描述
                                        DESC
  spec.version       = '3.1.0' # 库版本号
  spec.license       = { :type => 'BSD' } # 许可证  MIT
  spec.homepage      = 'https://github.com/tonymillion/Reachability' #主页
  spec.authors       = { 'Tony Million' => '[email protected]' } #作者
  spec.summary       = 'ARC and GCD Compatible Reachability Class for iOS and OS X.' #短描述
  spec.source        = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' } #源文件 :commit =>'' :tag =>spec.version 
  spec.module_name   = 'Rich'
  spec.swift_version = '4.0' #swift版本号

  spec.ios.deployment_target  = '9.0' #支持iOS版本
  spec.osx.deployment_target  = '10.10' #支持macos版本

  spec.source_files       = 'Reachability/common/*.swift' # 包含源文件
  spec.ios.source_files   = 'Reachability/ios/*.swift', 'Reachability/extensions/*.swift'
  spec.osx.source_files   = 'Reachability/osx/*.swift'

  spec.framework      = 'SystemConfiguration' # 引用framework
  spec.ios.framework  = 'UIKit'
  spec.osx.framework  = 'AppKit'

  spec.dependency 'SomeOtherPod' #依赖其他的pod 
end

这里有详细说明

  1. 创建SLICENSE文件,一般gitlab或者github上都有示例文件,可以对应着的修改,放在工程目录下
    5.验证specs文件
    pod lib lint .(或者.podspec文件)
    如果验证通过,即可,如果没有通过则需要修改错误,如果可以忽略的error,请用--verbose --allow-warnings --verbose显示出详细错误
  • 一般错误,1. source_files 文件目录找不到
    2. description 比summary 短,修改
    3. source 地址不对,或者tag不对,加v的tag,在没有指定具体tag号会有问题,重新打一个不加v的tag即可
  1. 验证通过之后,如果申请了trunk可以
    pod trunk push [私有库名称] [.podspec]
    或者 pod repo push [私有库名称] [.podspec]
  2. 验证添加成功
    pod search xxxxx
    如果搜不到,将~/Library/Caches/CocoaPods/search_index.json 文件删除,执行pod repo update ,再次执行pod search 重新生成索引,如果还没有搜到,说明添加有问题,或者搜索有问题。
  3. 项目中导入
    在Podfile 中添加
    source "远程仓库地址"
    pod 'xxx', :git => '源库', :tag => 'tag号'

补充更新私有库或者github三方库步骤

  1. 修改podspec文件的version发布版本号
  2. 添加tag
    相关命令操作:
  • git tag (-l) 显示所有的tag
  • git tag -m xxx 创建新的tag号
  • git push --tags 推送创建的tag到远程仓库
  • git tag -d *** 删除本地tag (*** 代表tag号)
  • git push origin:refs/tag/*** 删除远程tag (*** 代表tag号)
    当然如果是gitHub或者gitlab远程仓库,我们可以在可是界面做这些操作,如截图所示:


    组件化之私有库_第1张图片
    image.png
  1. pod trunk push [仓库名] [.podspec] 发布到仓库中。
  2. pod repo update --verbose 更新仓库

你可能感兴趣的:(组件化之私有库)