CocoaPods 私有库搭建

本文源自本人的学习记录整理与理解,其中参考阅读了部分优秀的博客和书籍,尽量以通俗简单的语句转述。引用到的地方如有遗漏或未能一一列举原文出处还望见谅与指出,另文章内容如有不妥之处还望指教,万分感谢。

制作远程私有库分为以下几个步骤:

创建私有 Git 远程仓库;
创建私有 CocoaPods 远程索引库;
创建 Pod 所需要的项目工程文件,并上传到 Git 远程私有库;
验证 podspec 描述文件;
向私有 CocoaPods 远程索引库提交 podspec 描述文件;
使用 Pod 库;

快速开整:

cd /Users/mac/Desktop/XXEncryptKitCes 

pod lib create XXEncryptKit

cd /Users/mac/Desktop/XXEncryptKitCes/XXEncryptKit/Example 

pod install

cd /Users/mac/Desktop/XXEncryptKitCes/XXEncryptKit 

git add .

git commit -m '第一次提交0.1.0'

git remote add origin https://gitee.com/alvinsunny/XXEncryptKit.git

git push origin master -f

git tag 0.1.1

git push --tags

git pull origin master --allow-unrelated-histories

#创建本地私有索引库

cd .cocoapods/repos

#pod repo add 索引库名字  索引库地址

pod repo add XXEncryptKitSpec https://gitee.com/alvinsunny/XXSpecs.git

#创建完成

pod lib lint XXEncryptKitSpec.podspec --allow-warnings
或
pod lib lint xxx.podspec --verbose --use-libraries --allow-warnings --no-clean --sources='http://code.gome.inc/gitlab/MBPrivatePods/MBSpecs.git,https://github.com/CocoaPods/Specs'

pod repo push XXEncryptKitSpec XXEncryptKit.podspec --allow-warnings

Validating spec
 -> XXEncryptKit (0.1.1)
    
Updating the `XXEncryptKitSpec' repo

Adding the spec to the `XXEncryptKitSpec' repo

 - [Add] XXEncryptKit (0.1.1)

Pushing the `XXEncryptKitSpec' repo

执行过程


#1. 创建命令 ProjectName:你的工程名
pod lib create ProjectName

#2. 选择编程语言
What language do you want to use?? [ Swift / ObjC ]
> Objc  

#3.  在你的项目中是否创建一个demo工程,为了方便测试,我选择了Yes
Would you like to include a demo application with your library? [ Yes / No ]
 > Yes  

#4.  测试框架选择哪一个
Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > None

#5. 要不要做视图测试
Would you like to do view based testing? [ Yes / No ]
 > Yes

#6. 类前缀名
What is your class prefix?
 > XSD

创建完项目会自动打开,项目目录结构如下:

├── XXEncryptKit
│   ├── Assets
│   └── Classes
│       └── ReplaceMe.m
├──  XXEncryptKit.podspec
├── Example
├── LICENSE
├── README.md
└── _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj
  1. ReplaceMe.m 替换为自己的代码

  2. 在Example 目录下 pod install 即可使用

编辑CocoaPods的配置文件 -- XXEncryptKit.podspec

要求:

  • 代码版本要与项目的tag对应

  • s.homepage和s.source 必须正确

  • 不可使用中文标点

  • s.ios.deployment_target 项目最低版本号必须和Xcode 中一致

  • cd 到模板目录(最外部) 验证 podspec 文件: pod lib lint --allow-warnings
    --allow-warnings:忽略警告

项目发布

1、 终端移到该项目文件下执行git的相关命令

2、在gitHub创建git私有库

3、在终端执行git提交命令

详细过程


#1. 开发玩🤩代码cd到工程目录的Example文件
localhost:BasisProject mac$ cd /Users/mac/Desktop/XSDLoading/Example

#1.1  pod install
localhost:Example mac$ pod install

Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

#1.2 cd 到工程目录
ocalhost:BasisProject mac$ cd /Users/mac/Desktop/XSDLoading

#2. 提交到本地缓冲区
localhost:XSDLoading mac$ git add .

#3. 描述信息
localhost:XSDLoading mac$ git commit -m '第一次提交0.1.0'
[master b0ecfb1] 第一次提交0.1.0
~~~~~~~~~~
 create mode 100644 Example/Pods/Target Support Files/XSDLoading/XSDLoading-Info.plist
 create mode 100644 Example/Pods/Target Support Files/XSDLoading/XSDLoading-
 delete mode 100644 XSDLoading/Classes/ReplaceMe.m
 create mode 100755 XSDLoading/Classes/UIImage+XXXImageParser.h
 create mode 100755 XSDLoading/Classes/UIImage+XXXImageParser.m

#4. 连接远程仓库
localhost:XSDLoading mac$ git remote add origin https://gitee.com/alvinsunny/XSDLoading.git

#5. 强制提交
localhost:XSDLoading mac$ git push origin master -f

#git push -f origin master//将本地库的代码推到远程库
#git push --tags//将本地创建的tag推到远程库

Enumerating objects: 87, done.
Counting objects: 100% (87/87), done.
Delta compression using up to 8 threads
Compressing objects: 100% (78/78), done.
Writing objects: 100% (87/87), 32.17 KiB | 2.14 MiB/s, done.
Total 87 (delta 23), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/alvinsunny/XSDLoading.git
 + 14bfa1a...b0ecfb1 master -> master (forced update)

#6. 这里的tag就是弄个版本记录
localhost:XSDLoading mac$ git tag 0.1.0

#7. 提交tag
localhost:XSDLoading mac$ git push --tags

Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/alvinsunny/XSDLoading.git
 * [new tag]         0.1.0 -> 0.1.0

#git pull origin master
localhost:XSDLoading mac$ git pull origin master --allow-unrelated-histories

From https://gitee.com/alvinsunny/XSDLoading
 * branch            master     -> FETCH_HEAD
Already up to date.

#8. 添加spec到远程仓库
localhost:XSDLoading mac$ pod repo add XSDLoadingSpec https://gitee.com/alvinsunny/PTBSpecs.git

Cloning spec repo `XSDLoadingSpec` from `https://gitee.com/alvinsunny/PTBSpecs.git`

#9. 验证 .podspec 文件
localhost:XSDLoading mac$ pod lib lint XSDLoading.podspec --allow-warnings

 -> XSDLoading (0.1.0)
    - WARN  | summary: The summary is not meaningful.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
XSDLoading passed validation.
验证成功!!!!!! 😁

#10. 推送 .podspec文件到远端
localhost:XSDLoading mac$ pod repo push XSDLoadingSpec XSDLoading.podspec --allow-warnings

Validating spec
 -> XSDLoading (0.1.0)
    - WARN  | summary: The summary is not meaningful.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | xcodebuild:  note: Building targets in parallel
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
Updating the `XSDLoadingSpec' repo
Adding the spec to the `XSDLoadingSpec' repo

 - [Add] XSDLoading (0.1.0)

Pushing the `XSDLoadingSpec' repo

localhost:XSDLoading Mac$

成功!!!!!!!!😁😁😁😁😁😁😁😁😁

集成到主项目


platform :ios, '9.0'

source 'https://gitee.com/alvinun/PTBSpecs.git'

target 'XXXMainUIKit' do

pod 'XSDLoading'

end

拉取项目


#pod install --repo-update

[localhost:XXMainUIKit mac$ pod install --repo-update

Updating local specs repositories
  $ /usr/bin/git -C /Users/mac/.cocoapods/repos/gitee-alvinsunny-ptbspecs fetch
  origin --progress
Analyzing dependencies
Downloading dependencies
Installing XSDLoading (0.1.0)
Generating Pods project
Integrating client project
Pod installation complete! There are 3 dependencies from the Podfile and 3 total pods installed.
localhost:XXMainUIKit Mac$ 

常见git命令


git init         #//初始化
git status        #//查看状态
git add .        #//添加文件到缓冲区
git commit -m "描述"        #//从缓冲区提交代码到仓库
git tag -a '0.0.1'  -m '描述'        #//添加tag
git tag         #//查看tag
git tag -d '0.0.1'        #//删除tag
git remote add origin https://github.com/xxx.git        #//关联本地仓库和远程仓库。
git push -f origin master        #//将本地库的代码推到远程库
git push --tags        #//将本地创建的tag推到远程库
git push origin :0.0.1        #//删除tag
# 安装并设置 git,全局配置用户名邮箱配置,也可以在项目根目录对单个仓库进行设置,去除--global参数即可
git config --global user.name "Yours Name"
git config --global user.email "xxx@xx.com"
git config --list

常用分支管理命令

git clone xxx (xxx为刚刚复制的仓库链接)

# 查看所有分支
git branch -a

# 新建分支
git branch xxx (xxx填写你的分支名称)

# 切换到某一分支
git checkout xxx (xxx填写要切换的分支名称)

# 提交代码到指定分支
git push origin xxx (xxx为要提交代码的分支名称)

# 删除本地分支和远程分支(注意删除前先,确定自己不在要删除的分支上)

# 1. 切换到要操作的项目文件夹
   cd  ProjectPath

# 2. 查看项目分支(包括本地和远程)
git branch -a

# 3. 删除本地分支 
git branch -d 分支名

# 4. 删除远程分支
git push origin –delete 分支名 

# 5. 查看删除后的分支

git branch -a


组件化私有库踩坑笔记
podspec常用语法
podspec官方语法参考

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,402评论 6 499
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,377评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,483评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,165评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,176评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,146评论 1 297
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,032评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,896评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,311评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,536评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,696评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,413评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,008评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,659评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,815评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,698评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,592评论 2 353

推荐阅读更多精彩内容