美文网首页私有库
利用cocapods制作私有pod库

利用cocapods制作私有pod库

作者: YannChee | 来源:发表于2019-02-14 16:56 被阅读10次

    之前写了 利用cocapods制作公有pod库https://www.jianshu.com/p/99e9c199bd64 ,其实制作私有pod库 的步骤跟公有pod库大部分一致,区别在于:

    • 公有库是直接 上传 xxxx.podspec文件到 CocoaPods/repo
    pod trunk push QYAnyWaterfallLayout.podspec
    
    • 私有库是
      1.先要私有私有库并和项目地址做关联,使用命令
    pod repo add 私有库名称 私有库地址
    例如 :  
    pod repo add QYPrivateLibs https://github.com/YannChee/QYPrivateLibs.git
    

    2.向私有的库里添加podspec文件

    pod repo push 私有库名称 xxx.podspec
    例如:
    pod repo push QYPrivateLibs QYPrivateLibs.podspec
    

    还有就是使用上的区别:
    当项目使用私有库时需要在podfile文件中添加私有库的源地址,而公有库可以不添加

    source 'https://github.com/YannChee/QYPrivateLibs.git'
    

    简单记录一下.

    1.创建一个私有的项目

    2.创建xxx.podspec

    cd QYPrivateLibs
    pod spec create QYPrivateLibs

    3.编辑xxx.podspec文件

    Pod::Spec.new do |s|
    
      s.name         = "QYPrivateLibs"
      s.version      = "0.0.1"
      s.summary      = "这个是我的私有pod库"
    
      s.description  = <<-DESC
                      这里保存着我的私有库用到的私有框架和文件
                       DESC
    
      s.homepage     = "https://github.com/YannChee"
     
      s.license      = "MIT"
      s.author             = { "YannChee" => "yannchee@163.com" }
      
      s.platform     = :ios, "8.0"
    
      s.source       = { :git => "https://github.com/YannChee/QYPrivateLibs.git", :tag => "#{s.version}" }
    
      s.source_files  = "QYPrivateLibs/**/*"
    
      s.requires_arc = true
    end
    

    4. 把这些改动上传到Git,并设置tag

    5.验证xxx.podspec文件

    pod spec lint QYPrivateLibs.podspec
    

    6.添加一个私有库并和项目地址做绑定

    pod repo add QYPrivateLibs https://github.com/YannChee/QYPrivateLibs.git
    

    7.向私有的库里添加podspec文件

    pod repo push QYPrivateLibs QYPrivateLibs.podspec
    

    8.以上部分私有库的制作基本完成了,但使用中需要注意,如果使用了私有库,必须 要podfile中指定私有库的source

    例如,我们建立一个测试项目,不指定私有库source


    不指定私有库 source

    在执行pod install 时直接报错

    Unable to find a specification for `QYPrivateLibs`

    在podfile文件中添加源地址后执行pod install

    use_frameworks!
    
    platform :ios, '12.0'
    
    source 'https://github.com/YannChee/QYPrivateLibs.git'
    
    target 'QYPrivateDemoProj' do
    
    pod 'QYPrivateLibs'
      
    end
    

    此时私有库成功添加到项目中


    相关文章

      网友评论

        本文标题:利用cocapods制作私有pod库

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