CocoaPods私有库的创建-iOS版

CocoaPods私有库的创建-iOS版

  • 默认开启VPN
  • 无指定说明终端命令都cd到本地项目最外层

1.创建仓库

json 复制代码
github:Your repositorites  ->  New -> Repository name*  中输入仓库名 -> Create repository  (其他选项默认)

2.创建项目

终端

bash 复制代码
cd 一个项目存放路径
c 复制代码
pod lib create xxx(DEACRollingNumberLabel) (项目名称 最好跟仓库名一致) 
json 复制代码
ryan@RyandeMac-mini Documents % pod lib create DEACRollingNumberLabel
Cloning `https://github.com/CocoaPods/pod-template.git` into `DEACRollingNumberLabel`.
Configuring DEACRollingNumberLabel template.

------------------------------

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 ] // 选择语言
 > swfit

Would you like to include a demo application with your library? [ Yes / No ] // 是否添加demo
 > Yes

Which testing frameworks will you use? [ Quick / None ] // 是否使用Framwork框架
 > None

Would you like to do view based testing? [ Yes / No ] // 否需要做接界面调试test
 > No

Running pod install on your new library.

Analyzing dependencies
Downloading dependencies
Installing DEACRollingNumberLabel (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `DEACRollingNumberLabel.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'DEACRollingNumberLabel/Example/DEACRollingNumberLabel.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`.

成功后会自动创建并打开Xcode显示该项目

项目目录

根目录

3.导入关键代码文件

.podspec的描述中已给出相应的路径

ini 复制代码
s.source_files = 'DEACRollingNumberLabel/Classes/**/*'

只需要把该目录下的文件替换掉即可

4.本地项目关联至github仓库

终端 cd 到本地项目根目录

bash 复制代码
ryan@RyandeMac-mini Documents % cd /Users/ryan/Documents/DEACRollingNumberLabel 

任何执行一下命令

json 复制代码
git add .
git commit -m "xxx" // 提交或更新的内容描述
git branch -M main
git remote add origin xxx (https://github.com/zhigangwu/DEACRollingNumberLabel.git) // 此处为github上项目源(source)地址 
git push -u origin main
json 复制代码
执行 git push -u origin main 返回如下信息表面关联成功 刷新github上的仓库即可看到上传的内容

ryan@RyandeMac-mini DEACRollingNumberLabel % git push -u origin main
Enumerating objects: 71, done.
Counting objects: 100% (71/71), done.
Delta compression using up to 8 threads
Compressing objects: 100% (64/64), done.
Writing objects: 100% (71/71), 27.22 KiB | 6.80 MiB/s, done.
Total 71 (delta 16), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (16/16), done.
To https://github.com/zhigangwu/DEACRollingNumberLabel.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

github仓库关联后目录

5.修改.podspec内容

.podspec默认内容

json 复制代码
Pod::Spec.new do |s|
  s.name             = 'DEACRollingNumberLabel'  // 库名称,不能跟现有cocoapods仓库里的库名同名
  s.version          = '0.1.0' // 版本号 延迟到第五步修改
  s.summary          = 'A short description of DEACRollingNumberLabel.' // 描述

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
TODO: Add long description of the pod here.
  // description指的是对库的描述,平时我们使用pod search 库名的时候,每个库有一个简单的介绍,指的就是这个description
                       DESC

  s.homepage         = 'https://github.com/12740181/DEACRollingNumberLabel' // 仓库地址 一般都填写git仓库的主页URL
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { '12740181' => '1402832352@qq.com' } // 作者 联系方式
  s.source           = { :git => 'https://github.com/12740181/DEACRollingNumberLabel.git', :tag => s.version.to_s }
// 源地址 及 tag 版本
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '10.0' // 库发布的iOS适配版本号,一般指最低支持的iOS版本

  s.source_files = 'DEACRollingNumberLabel/Classes/**/*' // 库的源码,需要明确指定,pod编译打包库时编译的就是这里指定的源码,一般都以通配符形式匹配
  
  # s.resource_bundles = {
  #   'PodspecLib' => ['PodspecLib/Assets/*.png']
  # }
# resource_bundles指的是资源文件,一般指图片、xib、storyboard、配置文件等
  # s.public_header_files = 'Pod/Classes/**/*.h'
  // 开放的公共头
  # s.frameworks = 'UIKit', 'MapKit'
  // 私有库需要依赖系统的哪些framework,需要这里明确指定
  # s.dependency 'AFNetworking', '~> 2.3'
  // 私有库如果需要依赖其他第三方pod,需要这里指定,多个时需要同样格式指定多个
end

修改完.podspec文件内容后

json 复制代码
cd 到本地目录的Example目录 并执行 pod install
pod 成功后即可在 Example for xxx 模块中进行相应的测试

import xxx 后如果发现无法获取到相应的库文件 则需要在相应的文件中加入 pubilc 权限修饰

测试通过后则进行下一步

6.更新tag

修改.podspec文件

arduino 复制代码
s.version = 'xxx' // 设置一个当前的tag版本号

终端 cd 到本地项目根目录

json 复制代码
cd /Users/ryan/Documents/DEACRollingNumberLabel
git add .
git commit -m 'xxx' // 可描述为更新xxxtag版本
git push -u origin main
git tag 1.0.0  // 与 s.version 中的一致
git push ---tags

刷新github线上仓库

7.验证.podspec文件

执行命令

json 复制代码
pod spec lint --allow-warnings --use-libraries
或
pod lib lint pod_test.podspec --allow-warnings --use-libraries
如果失败,报超时,可多试几次
json 复制代码
ryan@RyandeMac-mini DEACRollingNumberLabel % pod spec lint --allow-warnings --use-libraries

 -> DEACRollingNumberLabel (1.0.0)
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  note: Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'App' from project 'App')

Analyzed 1 podspec.

DEACRollingNumberLabel.podspec passed validation. // 证明验证成功

ryan@RyandeMac-mini DEACRollingNumberLabel % 

8.关联到远程索引库

在github上在创建一个仓库命名建议xxxSpec,作用就是把本地项目中的xxx.podspec文件与该仓库关联起来做一个单独的管理。该仓库同时也可以存放之后要创建的私有库的Spec文件。

创建好之后在生成个 README 以生成一个 main 主目录(没有主目录后续上传.podspec可能会失败)

创建好之后终端执行命令

复制代码
pod repo
json 复制代码
ryan@RyandeMac-mini DEACRollingNumberLabel % pod repo

cocoapods
- Type: git (remotes/origin/master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/ryan/.cocoapods/repos/cocoapods

coding-yecczzz-yecctencentspecs
- Type: git (master)
- URL:  https://e.coding.net/YeCcZzz/YeCcTencentSpecs.git
- Path: /Users/ryan/.cocoapods/repos/coding-yecczzz-yecctencentspecs

DEACProgressCardSpec
- Type: git (main)
- URL:  https://github.com/zhigangwu/DEACProgressCardSpec.git
- Path: /Users/ryan/.cocoapods/repos/DEACProgressCardSpec

trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/ryan/.cocoapods/repos/trunk

zhigangwu-deacprogresscard
- Type: git (main)
- URL:  https://github.com/zhigangwu/DEACProgressCard.git
- Path: /Users/ryan/.cocoapods/repos/zhigangwu-deacprogresscard

5 repos

终端会检索出本地已有的一些私有库,也可以通过

javascript 复制代码
~/.cocoapods/repos

直接查看本地已有的私有库

执行命令

json 复制代码
pod repo add AnimationCollectionSpec https://github.com/zhigangwu/AnimationCollectionSpec.git 
// pod repo add <远程存放.podspec的仓库名> + <远程存放.podspec的仓库git地址>
json 复制代码
Cloning spec repo `AnimationCollectionSpec` from `https://github.com/zhigangwu/AnimationCollectionSpec.git`
// 会把远程Spec仓库的克隆到本地 .cocoapods/repos 中

执行

json 复制代码
pod repo 或 ~/.cocoapods/repos 都可以看到新的Sepc仓库

执行

json 复制代码
pod repo push AnimationCollectionSpec DEACRollingNumberLabel.podspec --allow-warnings --use-libraries
// pod repo push <远程存放.podspec的仓库名> + <本地项目中的xxx.podspec文件名>

关联成功,本地的repos对应的仓库内容也会相应的更新

json 复制代码
Validating spec
 -> DEACRollingNumberLabel (1.0.0)
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  note: Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'App' from project 'App')

Updating the `AnimationCollectionSpec' repo


Adding the spec to the `AnimationCollectionSpec' repo

 - [Add] DEACRollingNumberLabel (1.0.0)

Pushing the `AnimationCollectionSpec' repo

至此可以找个项目来做验证下在podfile文件中添加如下内容

json 复制代码
source 'https://github.com/zhigangwu/AnimationCollectionSpec.git' // 此地址为管理.podspec文件的 Spec 仓库的git源地址
pod 'DEACRollingNumberLabel'
保存执行 pod install
相关推荐
星海拾遗6 小时前
git rebase记录
大数据·git·elasticsearch
ljh5746491197 小时前
PhpStorm 2022.3 版本中,修改使用 Git 提交时看到弹出式的对话框模式
ide·git·php·phpstorm
云闲不收9 小时前
git rebase
git
江上清风山间明月9 小时前
git pull和git checkout在恢复文件的区别
git·pull·checkout
海鸥8110 小时前
in argocd ‘/tmp/_argocd-repo/../.git/index.lock‘: No space left on
git·argocd
DisonTangor11 小时前
【小米拥抱开源】小米MiMo团队开源309B专家混合模型——MiMo-V2-Flash
人工智能·开源·aigc
尔嵘11 小时前
git操作
大数据·git·elasticsearch
好评12411 小时前
Linux文件上传git
linux·运维·git
yumgpkpm12 小时前
Iceberg在Cloudera CDP集群详细操作步骤
大数据·人工智能·hive·zookeeper·spark·开源·cloudera
大柏怎么被偷了13 小时前
【Git】企业级开发模型
git