Thursday, July 29, 2021

CocoaPods 私有化

一、创建所需要的代码仓库

  1. 创建 Spec 私有索引库(ZFSpec),用来存放本地spec
  2. 创建模块私有库(ZFPodProject),用来存放项目工程文件

二、私有索引库添加到本地 CocoaPods

操作命令:pod repo add {私有库名字} {私有库git地址}

打开终端,执行以下命令:

# cd 到本地的 CocoaPods 仓库cd ~/.cocoapods/repos# 将 ZFSpec 私有库添加到本地的 CocoaPods 仓库pod repo add ZFSpec https://gitee.com/xxx/zfspec.git

pod repo add操作.png

三、模块项目工程

1、创建

操作命令:pod lib create {模块名}

# cd 到可以创建的目录cd Desktop/Module# 创建模块项目pod lib create ZFPodProject

pod lib create操作.png

2、目录介绍

ZFPodProject
 ZFPodProject(私有库目录)
  Assets(资源文件存放目录)
  Classes(代码文件存放目录)
 Example(demo 目录)

将 Classes 文件夹中的 "ReplaceMe.swift" 文件删除,然后将自己所需要的代码文件放到这个目录下;将资源文件(图片,xib文件...)放到 Assets 文件夹下,如图:

项目文件目录.png

3、代码导入

cd 到 Example 文件下,然后pod install,更新 Example 项目的 pod

打开 Example 项目,Pod 下的 Development Pods 文件夹就是私有库代码

四、podspec 文件配置

1、修改 podspec 文件

语法参考网站:https://guides.cocoapods.org/syntax/podspec.html

podspec 文件注释

Pod::Spec.new do |s|# 项目名称 s.name    = 'ZFPodProject'# 版本号 s.version   = '0.1.0'# 项目摘要 s.summary   = 'A short description of GOOCR.'# 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 GOOCR的项目描述,这是G1项目个人私有库      DESC# 主页,这里要填写可以访问到的地址,不然验证不通过 s.homepage   = 'https://www.baidu.com' # s.screenshots  = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license   = { :type => 'MIT', :file => 'LICENSE' }# 作者 s.author   = { 'Zephyr' => '2049982764@qq.com' }# 项目地址,这里不建议使用ssh地址,会有警告,建议使用http和https,最好是https# 更改成自己的项目远程仓库地址 s.source   = { :git => 'https://gitee.com/ZF_AloneOwl/zfpod-project.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>' s.ios.deployment_target = '11.0' # 源码 s.source_files = 'ZFPodProject/Classes/**/*' # 资源文件 s.resource_bundles = { 'ZFPodProject' => [  'ZFPodProject/Assets/*.png',  'ZFPodProject/Assets/*.ttf' ] } # swift 版本 s.swift_versions=['5']# s.frameworks和s.dependency根据是否有依赖库来决定是否需要添加# 依赖的frameworks s.frameworks = 'UIKit', 'AVKit', 'Foundation'# 依赖的公开库或私有库,如有多个,可以重复声明 s.dependency 'Alamofire','~> 5.2.2' s.dependency 'Moya','~> 14.0.0'end

注:项目中的 Podfile 文件中默认 iOS 版本是 9.0(platform :ios, '9.0'),需要和 podspec 中设置的一致(s.ios.deployment_target = '11.0'),我这里需要将 Podfile 中的修改为 11.0。这里不修改,在 pod install 时可能会报错。

五、验证及上传

1、验证本地 podspec 文件有效性

验证有效性花费时间较长,建议先构建 demo,demo 中没有报错后,再进行验证

操作命令:pod lib lint [操作参数]

参数说明:

# 指定源,比如你的私有pod同时依赖了公有库和私有库,你必须指定源才行,因为默认只会去在公有源中查找对应的依赖--sources='私有库地址,公有库地址'# 显示详情--verbose# 当构建当前私有库时使用静态库的情况下使用--use-libraries# 跳过验证 pod 是否可以导入阶段--skip-import-validation# 允许警告--allow-warnings

示例:

pod lib lint --sources='https://gitee.com/ZF_AloneOwl/zfspec.git,https://github.com/CocoaPods/Specs.git' --verbose --use-libraries --skip-import-validation --allow-warnings

注:以上参数不一定全部使用,是项目情况使用

2、本地项目文件上传到远程仓库中

# 查看远程仓库地址git remote -v# 将本地项目与远程仓库相关联:git remote add origin {远程仓库地址}# 修改远程地址git remote set-url origin {远程仓库地址}# 拉取远端代码git pull origin master --allow-unrelated-historiesgit statusgit add .git commit -m '提交消息'git statusgit pull origin mastergit push origin master# tag 要与podspec文件中的版本号一致git tag -a 0.1.0 -m '提交消息'git push —tagsgit tag

3、podspec 文件本地和远程有效性的验证

操作命令:pod spec lint [操作参数]

pod spec lint --verbose --allow-warnings

注:操作参数见选项2

4、向私有 spec Repo 远程仓库中提交 podspec

操作命令:pod repo push {仓库名} {项目名}.podspec [操作参数]

pod repo push ZFSpec ZFPodProject.podspec --verbose --allow-warnings

注:操作参数见选项2

5、上传成功验证

完成以上步骤,就表示已经创建了一个 CocoaPods 私有库

前往文件夹 ~/.cocoapods/repos 去查看 ZFSpec 目录下的文件如下:......

原文转载:http://www.shaoqun.com/a/892275.html

跨境电商:https://www.ikjzd.com/

亚马逊全球开店制造:https://www.ikjzd.com/w/204.html

三维度:https://www.ikjzd.com/w/1312

outfit:https://www.ikjzd.com/w/938


一、创建所需要的代码仓库创建Spec私有索引库(ZFSpec),用来存放本地spec创建模块私有库(ZFPodProject),用来存放项目工程文件二、私有索引库添加到本地CocoaPods操作命令:podrepoadd{私有库名字}{私有库git地址}打开终端,执行以下命令:#cd到本地的CocoaPods仓库cd~/.cocoapods/repos#将ZFSpec私有库添加到本地的CocoaP
母婴团购网:https://www.ikjzd.com/w/716
olive:https://www.ikjzd.com/w/2025
四川推进有序开放 发力促进"回补消费":http://www.30bags.com/a/426577.html
四川瓦屋山不接待成都籍游客? 景区回应:谣言!正常接待中:http://www.30bags.com/a/225224.html
四川完美赏花手册 请在花海中吻我:http://www.30bags.com/a/416734.html
四川为全国旅游标准化探路 - :http://www.30bags.com/a/409798.html
我把女校花处破了 校花在教室把第一次给我了:http://lady.shaoqun.com/a/247321.html
打开腿闺蜜用黄瓜让我爽 和闺蜜一起磨豆腐的经历:http://lady.shaoqun.com/m/a/248347.html
招生在高校旁边开酒店的推广方式有争议:http://lady.shaoqun.com/a/428527.html
为什么大学附近有那么多小旅馆?大学生不都住校园吗?:http://lady.shaoqun.com/a/428528.html
大学周边的酒店往往供不应求。他们在里面做什么?你有过难忘的经历吗?:http://lady.shaoqun.com/a/428529.html
女人给你这四个暗示是因为想和你发生关系!:http://lady.shaoqun.com/a/428530.html

No comments:

Post a Comment