CocoaPods私有库配置笔记

作者: 0occ | 来源:发表于2016-01-06 13:27 被阅读7743次

    前情提要

    公司项目一直在用CocoaPods管理第三方包,自己也想着将项目中的公用模块抽离出来独立的包。所以研究了一下。

    准备工作

    github创建私有库 如testSpecs.git

    pod repo add testSpecs https://github.com/qgg/testSpecs.git

    github创建工具库 如QGGImagePicker 注意创建的时候勾选开源协议
    命令行创建模版工程
    pod lib create QGGImagePicker

    根据提示创建完成

    XXXXXX$ pod lib create QGGImagePicker
    Cloning `https://github.com/CocoaPods/pod-template.git` into `QGGImagePicker`.
    Configuring QGGImagePicker template.
    ------------------------------
    To get you started we need to ask a few questions, this should only take a minute.
    If this is your first time we recommend running through with the guide: 
     - http://guides.cocoapods.org/making/using-pod-lib-create.html
     ( hold cmd and double click links to open in a browser. )
    What language do you want to use?? [ ObjC / Swift ]
     > ObjC
    Would you like to include a demo application with your library? [ Yes / No ]
     > Yes
    Which testing frameworks will you use? [ Specta / Kiwi / None ]
     > None
    Would you like to do view based testing? [ Yes / No ]
     > No
    What is your class prefix?
     > QGG
    

    完成后打开工程目录如下:工具库主要在红框内容Classes目录下进行开发


    1.png

    修改工程下的.podspec文件,如

    
    # Be sure to run `pod lib lint QGGImagePicker.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             = "QGGImagePicker"
      s.version          = "0.0.1"
      s.summary          = "QGGImagePicker."
    
    # 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
                            A ImagePicker Like WeChat's ImagePicker
                           DESC
    
      s.homepage         = "https://github.com/infiniteQin/QGGImagePicker.git"
      # s.screenshots     = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
      s.license          = 'MIT'
      s.author           = { "changqin" => "changqin@ixiaopu.com" }
      s.source           = { :git => "https://github.com/infiniteQin/QGGImagePicker.git", :tag => s.version.to_s }
      # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
    
      s.platform     = :ios, '7.0'
      s.requires_arc = true
    
      s.source_files = 'Pod/Classes/**/*','Pod/Classes/**/**/*'
      #s.resource_bundles = {
      #  'QGGImagePicker' => ['Pod/Assets/*.png']
      #}
      #s.resources = "Pod/*.xcassets"
    
      # s.public_header_files = 'Pod/Classes/**/*.h'
      s.frameworks = "UIKit", "AssetsLibrary"
      s.dependency 'Masonry', '~> 0.6.3'
    end
    

    本地验证

    pod lib lint 
    

    验证成功后推送工程到github给如QGGImagePicker工具库打tag(和podspec中的版本保持一致)

    验证远程库

    pod spec lint
    

    看到输出如下内容就成功了

    QGGImagePicker.podspec passed validation.

    私用库中添加工具库

    pod repo push testSpecs QGGImgePicker.podspec
    

    使用

    pod search QGGImagePicker
    Podfile文件添加 pod 'QGGImagePicker', '~> 0.0.1'
    pod update --verbose --no-repo-update
    注意这时候会报错,解决办法
    pod spec lint --sources=‘https://github.com/qgg/testSpecs.git,https://github.com/CocoaPods/Specs'
    或者
    /.cocoapods/repos/testSpecs/下的内容copy到/.cocoapods/repos/master/Specs下

    支持****CocoaPods****公开库

    https://github.com/CocoaPods/Specs.git 下fork一份
    将私有库中的.podspec文件转成.json

    $ pod ipc spec QGGImagePicker.podspec >> QGGImagePicker.podspec.json
    

    将内容(目录结构如下)添加到CocoaPods/Specs提交待作者审核后即可

    2.png

    最后

    分享几篇我参考的文章
    https://cocoapods.org/
    http://www.cocoachina.com/ios/20150508/11785.html
    http://www.cocoachina.com/ios/20150228/11206.html

    相关文章

      网友评论

      • zhou某某: pod repo push FXSpecs TestLib.podspec

        Validating spec
        -> TestLib (0.1.0)
        - WARN | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred.

        [!] The repo `FXSpecs` at `../.cocoapods/repos/FXSpecs` is not clean 有人遇见这个问题吗 求解
        4de765d5dfc6:我也是碰到这歌问题
        第一次想把代码库push上去成功
        然后当我修改后,升级版本,在此push上去,就不行了
      • 新地球说着一口陌生腔调:你好 我的报错
        xuetianhhbdeMac-mini:hhbTestPod xuetianhhb$ pod lib lint

        -> hhbTestPod (0.1.0)
        - WARN | summary: The summary is not meaningful.
        - WARN | url: The URL (https://github.com/hhb19900618/hhbTestPod) is not reachable.

        [!] hhbTestPod did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
        [!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
        `echo "2.3" > .swift-version`.
        You can use the `--no-clean` option to inspect any issue.
        看风筝的小男孩:这个是有警告 直接命令后面加上 pod lib lint --allow-warnings就可以了;也可使用pod spec lint --allow-warning去验证
      • 肆意二货:s.dependency 依赖的库,在你pod你的私有库的时候会不会被下载下来?

      • 其实也没有:pod install
        报错
        [!] An unexpected version directory `Assets` was encountered for the
        怎么解决呀
      • 巴图鲁:膜拜
      • Laughingg:[iOS] xcodebuild: Returned an unsuccessful exit code.
        这个错误一直没过去
      • b96acac40a08:第三方库一直报错。。。。
      • Cocody:关于私有库更新到公开库:
        CocoaPods 1.0 以后,使用 pod trunk push 来提交,而不是文中描述的用 pull request 的形式。
      • jakend:写的挺好的。
      • 采香行处蹙连钱:问一个问题,私有库的gitignore应该怎样配置

      本文标题:CocoaPods私有库配置笔记

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