CocoaPods私有库搭建

CocoaPods 安装入门就不多说了可以看这个 https://www.jianshu.com/p/ab6411a05bc2

直切主题,开始搭建私有 spec repo (私有库master)

  • 首先在Github,GitLab,码云等创建仓库 这里就以github为例 名称为WFPodSpecs 仓库地址为https://github.com/iHZW/WFPodSpecs.git
    终端执行 pod repo add (私有配置仓库名称) (私有配置仓库git地址)
    pod repo add WFPodSpecs https://github.com/iHZW/WFPodSpecs.git
    
    执行上面命令之后,~/.cocoapods/repos目录下,就能看到WFPodSpecs这个仓库了
    cd ~/.cocoapods/repos
    
    特别提醒下各位, 一定要先把对新创建的WFPodSpecs仓库随便提交点东西,因为此时没有master分支,提交之后就有master分支, 如果不这样做的话,你会发现到后边会出现各种error 并且网上搜索也没有什么好的解决办法,这个是小编自己误打误撞解决的.
  • 接下来创建Pod组件 名称为WFUIKit
    到组件存放的文件下终端输入命令
    pod lib create WFUIKit
    
    以下是我创建时的终端信息
     hzw@HZWdeMacBook-Pro-2  ~/Desktop/WFUIKit  pod lib create WFUIKit
    Cloning `https://github.com/CocoaPods/pod-template.git` into `WFUIKit`.
    Configuring WFUIKit template.
    ! Before you can create a new library we need to setup your git credentials.
    
     What is your email?
     > 18516638588 @163.com            
    
    ! Setting your email in git to 18516638588 @163.com
      git config user.email "18516638588 @163.com"
    
    ------------------------------
    
    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: 
     - 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 ]
     > 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?
     > WF
    
    Running pod install on your new library.
    
    Analyzing dependencies
    Fetching podspec for `WFUIKit` from `../`
    Downloading dependencies
    Installing WFUIKit (0.1.0)
    Generating Pods project
    Integrating client project
    
    [!] Please close any current Xcode sessions and use `WFUIKit.xcworkspace` for this project from now on.
    Sending stats
    Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
    
     Ace! you're ready to go!
     We will start you off by opening your project in Xcode
      open 'WFUIKit/Example/WFUIKit.xcworkspace'
    
    To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.
    To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.
     hzw@HZWdeMacBook-Pro-2  ~/Desktop/WFUIKit  
    
    成功之后桌面WFUIKit文件夹下就有了WFUIKit 工程
屏幕快照 2019-07-23 16.50.35.png
我们可以看到WFUIKit/Classes这个文件夹下有一个.m文件ReplaceMe.m,将我们自己的代码放到这个里面,替换掉ReplaceMe.m这个文件。这里面就是我们私有库的代码。WFUIKit/Assets里面主要放一些资源文件。我加了一个测试代码,如图:
屏幕快照 2019-07-23 17.29.26.png
  • 将创建好的组件工程WFUIKit 上传到git上
    git init
    git add .
    git commit -am "init" 
    git remote add origin https://github.com/xxx/WFUIKit.git //先创建好WFUIKit仓库
    git push origin master 
    //一定要有标签,不然会有下面的警告
    //podspec文件中获取Git版本控制的项目需要tag号,
    git tag -m "first release" 0.0.1  
    git push --tags
    
  • 接下来就是配置
  • git init
    git add .
    git commit -am "init" 
    git remote add origin https://github.com/xxx/WFUIKit.git //先创建好WFUIKit仓库
    git push origin master 
    //一定要有标签,不然会有下面的警告
    //podspec文件中获取Git版本控制的项目需要tag号,
    git tag -m "first release" 0.0.2  
    git push --tags
    
  • 接下来就是配置WFUIKit.podspec 文件
    Pod::Spec.new do |s|
      s.name             = 'WFUIKit'
      s.version          = '0.1.0'
      s.summary          = 'A short description of WFUIKit.'
    
    
      s.description      = <<-DESC
    TODO: Add long description of the pod here.
                           DESC
    
      s.homepage         = 'https://github.com/iHZW/WFUIKit'
      s.license          = { :type => 'MIT', :file => 'LICENSE' }
      s.author           = { 'iHZW' => '18516638588@163.com' }
      s.source           = { :git => 'https://github.com/iHZW/WFUIKit.git', :tag => s.version.to_s }
    
      s.ios.deployment_target = '8.0'
    
      s.source_files = 'WFUIKit/Classes/**/*'
      
    end
    
    
    解释如下
    
    s.name :pod search 搜索的关键词,注意这里一定要和.podspec的名称一样
    s.version :版本号,每一个版本对应一个tag
    s.summary : 简介
    s.homepage : 项目主页地址
    s.license : 许可证
    s.author : 作者
    s.source : 项目的地址
    s.source_files : 需要包含的源文件
    s.resources: 资源文件
    s.dependency :依赖库
    s.ios.deployment_target = '8.0'  : 支持的pod最低版本
    
    s.source_files = 'WFUIKit/Classes/**/*'
    *匹配所有文件 **匹配所有子目录
    
    
    验证下WFUIKit.podspec 进入到WFUIKit文件夹下
    pod spec lint --allow-warnings
    
     -> WFUIKit (0.0.2)
        - WARN  | summary: The summary is not meaningful.
        - NOTE  | xcodebuild:  note: Using new build system
        - NOTE  | [iOS] xcodebuild:  note: Planning build
        - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    
    Analyzed 1 podspec.
    
    WFUIKit.podspec passed validation.
    
    //这就是验证通过了,  这一步可能会出现不同的error, tag值或者source_files 路径不对, 调整下就可以解决
    这里的tag和s.version值要保持统一
    source_files 路径可以试试以下几种
    s.source_files  = 'Classes/*.{h,m}'
    s.source_files  = 'Classes/MyUIKit.{h,m}'
    s.source_files  = 'Classes'
    s.source_files  = 'Classes/**/*.{h,m}'
    
    
  • 接下来就是将组建WFUIKit.podspec 上传到私有库 WFPodSpecs
pod repo push [本地Spec Repo名称] [podspec文件名]
//在WFUIKit文件夹下执行
pod repo push WFPodSpecs WFUIKit.podspec --verbose --use-libraries --allow-warnings
执行之后如果完全按照我的步奏一般是没有问题的, 不过之前因为没有对WFPodSpecs仓库提交代码,会报错,提示source-file error  或者提示 路径不匹配等问题,解决了好久哈哈
这个时候进入WFPodSpecs仓库下就可以看到提交成功的WFUIKit  同时git上也存在刚刚创建的组件库WFUIKit了
cd ~/.cocoapods/repos/WFPodSpecs

最后验证下   pod search WFUIKit  是否存在
  • 接下来就来测试下我们的组件库吧WFUIKit吧
在其他工程里测试下吧,配置下Podfile 文件
Podfile文件内容:

source私有spec仓库的git地址,而不是某个pod仓库的地址
source 'https://github.com/iHZW/WFPodSpecs.git'
pod 'WFUIKit' 
然后执行
pod install --verbose --no-repo-update  或 
pod update --verbose --no-repo-update
接下来Pods 文件下就有了我们刚刚创建的组件库WFUIKit了
屏幕快照 2019-07-23 18.50.30.png
修改podspec tag
1.git tag 版本号

2.查看tag                   git tag

3.删除本地其他tag     git tag -d 0.1.0

4.推送到远程             git push --tags

5.查询远程tag值         git ls-remote --tags origin

6.删除远程多余的tag   git push origin :0.1.0

7.重复第5部查看是否有多余的tag

转载文章地址 https://my.oschina.net/snOS/blog/2998642

他写的真的很不错,不过中间遇到不少error 还得Google,百度帮忙解决了, 记录下方便往后使用

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 项目组件化、平台化是技术公司的共同目标,越来越多的技术公司推崇使用pod管理第三方库以及私有组件,一方面使项目架构...
    swu_luo阅读 22,719评论 0 39
  • 最近在整理组件化相关的东西,其中有一项就是用pod管理内部的一些公共组件,为了加深印象,下面把具体步骤记录一下(注...
    依旧孤独阅读 4,256评论 0 1
  • 要解除循环依赖,引入包管理技术cocoapods会让我们更有效率。pod不允许组件间有循环依赖,若有pod ins...
    cs_mark阅读 6,442评论 0 1
  • Cocoapods是非常好用的一个iOS依赖管理工具,使用它可以方便的管理和更新项目中所使用到的第三方库,以及将自...
    Nash33阅读 6,325评论 0 50
  • 函数声明式 function 函数名() { } 特点: 可在任何地方调用 函数表达式 var 函数名 = fun...
    婳噫阅读 1,769评论 0 0

友情链接更多精彩内容