美文网首页iOS 组件化
CocoaPod创建私有库

CocoaPod创建私有库

作者: Misaki_yuyi | 来源:发表于2018-07-01 11:54 被阅读23次

    在码云(我的个人主页)上创建两个远程仓库,其中YYSpecs 用来存放本地的spec,YYToolProject是用来存放私有库代码的。

    1 创建本地索引

    首先 进入~/.cocoapods/repos目录 查看有一个master的目录,master就是cocoapod官网的索引源,现在要做的就是创建自己私有的Spec Repo.

    pod repo add [Private Repo Name] [GitHub HTTPS clone URL]
    pod repo add YYSpecs  https://gitee.com/yuyiios/YYSpecs.git
    
    ~:.cocoapods:repos目录.png

    然后可以看见master有个同级目录YYSpecs。私有Spec Repo就创建完成了。

    2.创建本地lib

    进入桌面目录,创建一个名为YYToolSet的pod

    pod lib create YYToolSet
    

    会有以下提示,按照问题回答就可以

    
    If this is your first time we recommend running through with the guide: 
     - https://guides.cocoapods.org/making/using-pod-lib-create.html
     ( hold cmd and double click links to open in a browser. )
    
    
    What platform do you want to use?? [ iOS / macOS ]
     > 
    ios
    What language do you want to use?? [ Swift / ObjC ]
     > ObjC
    
    Would you like to include a demo application with your library? [ Yes / No ]
     > No
    
    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?
     > YY
    
    在Finder中,将/YYToolSet/Classes目录下的ReplaceMe.m删除 替换成自己的文件,如图。 替换掉ReplaceMe文件.png

    打开工程,查看YYToolSet.podspec文件

    • s.version 是pod的版本信息 这个后面打tag的时候用的到
    • s.summary 是简短的描述
    • s.source 是项目远程仓库的地址,这里不要用SSH,用HTTPS。
    • s.homepage 是项目主页地址 就是HTTPS地址后面去掉.git 就可以
    • s.source_files 是项目的文件 就是刚才替换ReplaceMe.m的那些文件
    • s.resource_bundles 是资源文件
    • s.frameworks 是用到了系统的哪些库 例如UIKit、Foundation
    • s.dependency 是用到哪些第三方库 比如AFNetworking 有多个就写多个s.dependency
    • s.public_header_files 项目的公共头文件,举个例子,当引入Masonry、YTKNetwork的时候 可以创建一个header文件,然后将#import "Masonry.h" #import "YTKNetwork.h”写入进去
    配置文件.png

    3.验证本地lib

    修改完成后,切换到外面的YYToolSet目录,验证podspec文件。

    pod lib lint
    pod lib lint --verbose
    pod lib lint --allow-warnings
    pod lib lint --sources=https://gitee.com/yuyiios/YYSpecs.git
    pod lib lint --use-libraries
    
    • --verbose 假如有error,查看报错信息
    • --allow-warnings 假如有warning,可以通过来忽略错误信息通过验证
    • --sources 假如这个私有库还依赖其他的私有库,一定要指定私有库的索引源(就是我上文说的YYSpecs的git地址)--sources=https://github.com/artsy/Specs,master
    • --use-libraries 如果用了第三方的framework或者静态库,要加上。

    4.验证本地和远端的pod

    本地校验成功后,推送至远端,就是YYToolProject的git地址。进入外面的YYToolSet目录。执行命令。

    git remote add origin [GitHub HTTPS clone URL]
    git remote add origin https://gitee.com/yuyiios/YYToolProject.git
    git pull origin master
    

    有冲突先解决冲突

    git add .
    git commit -m 'fix'
    git push origin master
    

    然后给pod打上标签,并且推送至远端,注意这里的tag要和podspec文件里面的s.version对应起来。

    git tag -m '0.1.0标签' -a 0.1.0
    git push --tags
    git tag //查看标签
    

    打完标签后,执行

    pod spec lint
    

    pod lib lint和pod spec lint的区别是前者只会检验本地的pod,后者是本地和远端都会检验,所以之前用到的--allow-warning --sources --use-libraries 等命令的这里都要带上。

    5 推送至索引源仓库

    远端和本地都校验通过后就要将YYToolSet.podspec 推送至YYSpecs仓库中 成功后去~/.cocoapods/repos/YYSpecs 有个YYToolSet目录 有个0.1.0的版本。

    pod repo push [Repo名] [podspec 文件名字]
    pod repo push YYSpecs YYToolSet.podspec
    

    最后验证一下

    pod search YYToolSet 
    -> YYToolSet (0.1.0)
       工具集 YYToolSet.
       pod 'YYToolSet', '~> 0.1.0'
       - Homepage: https://gitee.com/yuyiios/YYToolProject
       - Source:   https://gitee.com/yuyiios/YYToolProject.git
       - Versions: 0.1.0 [YYSpecs repo]
    (END)
    

    新建一个空项目,导入私有库验证一下,这里一定要带上source 就是YYToolSet所在索引源的远端地址。

    pod init 
    vim Podfile
    
    source 'https://gitee.com/yuyiios/YYToolProject.git'
    # platform :ios, '9.0'
    
    source 'https://gitee.com/yuyiios/YYSpecs.git'
    # platform :ios, '9.0'
    
    target 'None' do
      pod 'YYToolSet', '~> 0.1.0'
      # use_frameworks!
    
      # Pods for None
    
    end
    
    验证通过.png

    相关文章

      网友评论

        本文标题:CocoaPod创建私有库

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