美文网首页
CocoaPods 私有仓库的创建

CocoaPods 私有仓库的创建

作者: 愚虫 | 来源:发表于2017-09-29 09:38 被阅读97次

    一、创建Spec Repo管理我们创建的所有pod spec

    首先,创建一个像 master 一样的存放版本描述文件的git仓库。

    open ~/.cocoapods/repos
    
    
    QQ20170927-100119@2x.png

    以上是我本地repos的目录:master是官方的目录,PrivatePodspec是我们自己的私有库目录。

    以码云为例

    3831145-d9402f3d5fe8d797.jpeg

    回到终端,将这个远程的私有版本仓库添加到本地

    pod repo add PrivatePodspec https://git.oschina.net/XXXX/PrivatePodspec.git
    
    
    //更新所有
    pod repo update
    //更新指定
    pod repo update XXX
    //删除
    pod repo remove XXX
    

    二、创建准备制作成podspec的项目

    将仓库克隆到本地,添加你的代码文件、仓库名.podspec 描述文件

    pod spec create XXX//XXX 最好和项目名一致
    

    以AFNetworking为例

    Pod::Spec.new do |s|
      s.name     = 'AFNetworking' # 项目名称
      s.version  = '3.1.0'  # 版本号 与 你仓库的 标签号 对应
      s.license  = 'MIT'  # 开源证书
      s.summary  = 'A delightful iOS and OS X networking framework.' # 项目简介
      s.homepage = 'https://github.com/AFNetworking/AFNetworking'# 仓库的主页,必须访问通过
      s.social_media_url = 'https://twitter.com/AFNetworking'# 个人主页
      s.authors  = { 'Mattt Thompson' => 'm@mattt.me' } # 作者信息
      s.source   = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => s.version, :submodules => true }#你的仓库地址,不能用SSH地址
      s.requires_arc = true# 是否启用ARC
      
      s.public_header_files = 'AFNetworking/AFNetworking.h'
      s.source_files = 'AFNetworking/AFNetworking.h'
      
      pch_AF = <<-EOS
    #ifndef TARGET_OS_IOS
      #define TARGET_OS_IOS TARGET_OS_IPHONE
    #endif
    
    #ifndef TARGET_OS_WATCH
      #define TARGET_OS_WATCH 0
    #endif
    
    #ifndef TARGET_OS_TV
      #define TARGET_OS_TV 0
    #endif
    EOS
      s.prefix_header_contents = pch_AF
      
      s.ios.deployment_target = '7.0' #项目最低支持版本
      s.osx.deployment_target = '10.9'
      s.watchos.deployment_target = '2.0'
      s.tvos.deployment_target = '9.0'
      #子目录
      s.subspec 'Serialization' do |ss|
        ss.source_files = 'AFNetworking/AFURL{Request,Response}Serialization.{h,m}'
        ss.public_header_files = 'AFNetworking/AFURL{Request,Response}Serialization.h'
        ss.watchos.frameworks = 'MobileCoreServices', 'CoreGraphics'
        ss.ios.frameworks = 'MobileCoreServices', 'CoreGraphics'
        ss.osx.frameworks = 'CoreServices'
      end
    
      s.subspec 'Security' do |ss|
        ss.source_files = 'AFNetworking/AFSecurityPolicy.{h,m}'
        ss.public_header_files = 'AFNetworking/AFSecurityPolicy.h'
        ss.frameworks = 'Security'
      end
    
      s.subspec 'Reachability' do |ss|
        ss.ios.deployment_target = '7.0'
        ss.osx.deployment_target = '10.9'
        ss.tvos.deployment_target = '9.0'
    
        ss.source_files = 'AFNetworking/AFNetworkReachabilityManager.{h,m}'
        ss.public_header_files = 'AFNetworking/AFNetworkReachabilityManager.h'
    
        ss.frameworks = 'SystemConfiguration' #依赖库
      end
    
      s.subspec 'NSURLSession' do |ss|
        ss.dependency 'AFNetworking/Serialization'
        ss.ios.dependency 'AFNetworking/Reachability'
        ss.osx.dependency 'AFNetworking/Reachability'
        ss.tvos.dependency 'AFNetworking/Reachability'
        ss.dependency 'AFNetworking/Security'
    
        ss.source_files = 'AFNetworking/AF{URL,HTTP}SessionManager.{h,m}'
        ss.public_header_files = 'AFNetworking/AF{URL,HTTP}SessionManager.h'
      end
    
      s.subspec 'UIKit' do |ss|
        ss.ios.deployment_target = '7.0'
        ss.tvos.deployment_target = '9.0'
        ss.dependency 'AFNetworking/NSURLSession'
    
        ss.public_header_files = 'UIKit+AFNetworking/*.h'
        ss.source_files = 'UIKit+AFNetworking'
      end
    end
    
    

    三、创建并提交MyLib pod库的pod spec文件到私有仓库

    这里我要说一下一个坑,用 oschina 创建私人仓库时, 在验证时可能会找不到 MIT LICENSE证书,将其中的

    s.license      = "MIT"
    #修改为,指定文件
    s.license      = { :type => "MIT", :file => "LICENSE" }
    

    然后开始验证我们的仓库配置是否正确,并按照要求进行修改(一般出现错误警告,需要添加 --allow-warnings,就可以通过“本地”验证)

    pod lib lint --allow-warnings
    

    验证成功后出现

    XXX passed validation.
    

    这里提示我们需要给远程仓库打上与本地仓库 .podspec 相同的 Tag 值。

    git tag -a 0.1.0 -m '0.1.0标签'
    
    git push --tags
    

    最后将我们的代码仓库的描述信息,push 到我们的版本仓库中

    pod repo push PrivatePodspec XXX.podspec --allow-warnings
    

    四、常见错误

    1. pod lib lint时候常见的错误
    [!] DemoPodSpecs did not pass validation, due to 2 warnings (but you can use --allow-warnings to ignore them).
    You can use the --no-clean option to inspect any issue.
    

    解决办法:用 pod lib lint --allow-warnings 命令

    [!] 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
    
    

    解决办法:运行 echo 3.0 > .swift-version

    1. pod repo push
    The name.podspec specification does not validate.
    

    解决办法:pod repo push DemoPodSpecs DemoPodSpecs.podspec --verbose --use-libraries --allow-warnings

    /usr/bin/git -C /Users/.cocoapods/repos/DemoPodSpecs -C
    /Users/.cocoapods/repos/DemoPodSpecs push origin master
    fatal: repository '' not found
    

    解决办法:到 /Users/.cocoapods/目录下查看私有pod库是否存在

     ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/Shenjinghao/JHDynamicFont.git /var/folders/lc/zl333w0s6t12qjdfl0_brmdh0000gn/T/d20170315-37512-16fmh2q --template= --single-branch --depth 1 --branch 0.0.1
    
    

    出现上面错误的原因是没有为项目打上tag,或者打上tag没有推到远程仓库,在teminal输入下面命令

     git tag -a 1.0.0 -m 'v1.0.2'
     git push --tags
    

    【公共仓库】

    想创建开源的Pod库,就要注册一个CocoaPods账号,我们使用终端注册, email 用你的 GitHub 邮箱

    pod trunk register GitHub_email 'user_name' --verbose
    
    

    等终端出现下面文字,CocoaPods 会发一个确认邮件到你的邮箱上,登录你的邮箱进行确认。

    [!] Please verify the session by clicking the link in the verification email that has been sent to you_email@163.com
    

    注册成功!

    确认后再终端输入

    pod trunk me
    
    pod trunk push XXX.podspec
    

    相关文章

      网友评论

          本文标题:CocoaPods 私有仓库的创建

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