美文网首页iOS相关
私有CocoaPods库的搭建与使用

私有CocoaPods库的搭建与使用

作者: Archerlly | 来源:发表于2016-08-09 01:23 被阅读781次

    整个过程需要两个代码仓库, 一个用于存放spec文件, 一个用于存放代码

    创建本地Spec

    pod repo add AAA(私有spec库名称) YYY.git(第一个仓库)
    pod lib create BBB(私有pod库名称)

    链接远端代码库

    git add .
    git commit -s -m "Initial Commit of Library"
    git remote add origin XXX.git(第二个仓库)
    git push origin master

    spec文件中通过tag获取对应版本的源文件,所以我们要打上一个tag

    git tag 0.1.0
    git push --tags

    配置Podspec文件(大部分自动生成了)

    Pod::Spec.new do |s|
        s.name             = 'SCDNA_UI'     #pod search 中使用的名字
        s.version          = '0.2.0'                #上文中指定的tag
        s.summary          = ‘short name’       #简称
        s.description      = <<-DESC            #详细介绍 <<-DESC  XXX  DESC 固定格式
                          ~~~~ detail description ~~~~
                           DESC
    
        s.homepage         = 'git@code.SnowCheng.com:team/scdna.git'
        s.license          = { :type => 'MIT', :file => 'LICENSE' }
        s.author           = { 'snowCheng' => 'snowCheng@126.com' }
        s.source           = { :git => 'XXX.git', :tag => s.version.to_s}   #第二个代码库
        s.ios.deployment_target = '8.0'
        s.frameworks = 'UIKit'                              #所需的framework,多个用逗号隔开
        s.source_files = 'SCDNA_UI/Classes/**/*'                #仓库的源文件(**/* 一二级目录下的所有文件) 如果有多个目录下则用逗号分开,如果需要在项目中分组显示,需要用subspec单独设置
        s.resource = 'SCDNA_UI/Assets/*.bundle'             #资源文件地址
        s.prefix_header_file = 'SCDNA_UI/Classes/SCDNA_UI.h'    #PCH文件
        s.dependency 'Masonry','~>1.0.1'                        #项目依赖的其他库,如果有多个需要填写多个
        s.dependency 'YYText'
        s.dependency 'Charts'
    
    
    # s.public_header_files = 'SCDNA_UI/Classes/*.h'            #公开头文件
    # s.resource_bundles = {                                #资源文件地址
    #     'SCDNA_UI' => ['SCDNA_UI/Assets/*.bundle']
    # }
    
    #项目中分组显示, 得如下配置
    #s.subspec 'Default' do |ss|
    #        ss.source_files         = 'SCDNA_UI/Classes/*'
    #        ss.prefix_header_file   = 'SCDNA_UI/Classes/SCDNA_UI.h'
    #    end
    
    #    s.subspec 'Button' do |ss|
    #        ss.source_files     = 'SCDNA_UI/Classes/Button/*'
    #        ss.dependency 'SCDNA_UI/Default'
    #        ss.dependency 'SCDNA_UI/Category'
    #    end
    
    #    s.subspec 'Category' do |ss|
    #        ss.source_files = 'SCDNA_UI/Classes/Category/*'
    #    end
    end
    

    验证Podspec文件

    pod lib lint
    pod lib lint --no-clean 查看错误详情
    pod lib lint --allow-warnings 允许警告(包括xcode编译的warning)

    向Spec Repo提交podspec

    pod repo push AAA(私有spec库名称) BBB.podspec(私有pod库名称)
    有警告时可能会不通过 需要使用--allow-warnings 或者 --verbose进行debug

    删除一个私有Spec Repo

    pod repo remove AAA(私有spec库名称)

    恢复一个私有Spec Repo

    pod repo add WTSpecs YYY.git(第一个仓库)

    使用

    1、根据Podspec中指定的version,去拉对应的tag,建议私有库稳定后使用,方便同时进行开发
    source "YYY.git"(第一个仓库)
    source "https://github.com/CocoaPods/Specs.git"
    pod “YXDNA_UI”

    2、直接拉最新的代码,建议私有库还没稳定时使用,不用每次都去push spec文件和打tag
    pod “YXDNA_UI”, :git => 'XXX.git'(第二个仓库)

    相关文章

      网友评论

        本文标题:私有CocoaPods库的搭建与使用

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