一、創(chuàng)建一個(gè)空的私有庫(kù)項(xiàng)目gitHub地址,用于存放私有庫(kù)項(xiàng)目概龄。gitHub 下創(chuàng)建一個(gè)空的repository昌腰,這里起名SBAIPractice,不勾選README.md 等坏挠。
創(chuàng)建后:
2.創(chuàng)建私有庫(kù) SBAIPractice,到自己的想要放pod項(xiàng)目的目錄下邪乍,執(zhí)行如下命令創(chuàng)建私有庫(kù):
pod lib create SBAIPractice
依次回答如下問(wèn)題:
最后一個(gè)為你的項(xiàng)目類名前綴
3.關(guān)聯(lián)第一步中創(chuàng)建的空git
由于pod lib創(chuàng)建pod工程時(shí)默認(rèn)已經(jīng)準(zhǔn)備了LICENSE降狠、README.md、.gitignore三個(gè)文件庇楞,若在github上創(chuàng)建新建空白項(xiàng)目pod時(shí)勾選了這三個(gè)文件榜配,則git pull時(shí)會(huì)產(chǎn)生沖突。解決方式:將pod工程目錄下與github項(xiàng)目沖突的文件刪除吕晌。
此外蛋褥,pod項(xiàng)目目錄下默認(rèn)準(zhǔn)備了.git倉(cāng)庫(kù),關(guān)聯(lián)時(shí)不用重新git init聂使。
cd到pod項(xiàng)目目錄下
執(zhí)行:
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Manchitor/SBAIPractice.git
git push -u origin main
git push 有時(shí)會(huì)報(bào)錯(cuò)超時(shí)壁拉,多試幾次。
第一步創(chuàng)建的空項(xiàng)目刷新會(huì)看到已經(jīng)關(guān)聯(lián)成功了
二柏靶、配置Pods工程的.podspec文件弃理。主要是s.version、s.summary屎蜓、s.source的編輯痘昌。
SBAIPractice.podspec的內(nèi)容如下:
s.name :pod search 搜索的關(guān)鍵詞,注意這里一定要和.podspec的名稱一樣
s.version :版本號(hào),每一個(gè)版本對(duì)應(yīng)一個(gè)tag
s.summary : 簡(jiǎn)介
s.homepage : 項(xiàng)目主頁(yè)地址
s.license : 許可證
s.author : 作者
s.social_media_url : 社交網(wǎng)址
s.source : 項(xiàng)目的地址
s.source_files : 需要包含的源文件
s.resources: 資源文件
s.requires_arc : 是否支持ARC
s.dependency :依賴庫(kù)
s.ios.deployment_target = ‘10.0' : 支持的pod最低版本
s.source_files = ‘pod_test/Classes//’炬转,這里表示匹配所有子目錄辆苔,表示匹配所有文件。
修改后SBAIPractice.podspec后扼劈,cd到Example文件夾下執(zhí)行pod install驻啤。檢查是否設(shè)置正確。
代碼更新后先關(guān)閉workspace荐吵,一定要執(zhí)行:pod install 來(lái)更新骑冗,更新完需要重新打開(kāi)workspace。
1.打標(biāo)簽先煎,推送到遠(yuǎn)程贼涩。重點(diǎn):tag打的版本號(hào)必須和podspec中的s.version值相同
CocoaPods進(jìn)行倉(cāng)庫(kù)版本管理時(shí),就是通過(guò).podspec文件中s.version的值到git遠(yuǎn)程倉(cāng)庫(kù)上找與之相同的tag標(biāo)簽的版本薯蝎。
這里將s.version改為: s.version = ‘1.0.0'
git add .
git commit -m '設(shè)置podspec文件為1.0.0'
git push -u origin main
git tag 1.0.0
git push —tags
查看所有tag內(nèi)容:git tag -l -n
gitHub中效果為:
2.驗(yàn)證.podspec文件的格式是否正確遥倦,必須打完tag才能驗(yàn)證,且必須驗(yàn)證占锯,否則后面執(zhí)行pod repo push或pod trunk push一定失敗袒哥。
cd到SBAIPractice目錄缩筛,執(zhí)行命令
//--allow-warnings:加上該選項(xiàng),驗(yàn)證時(shí)如果有警告會(huì)忽略警告统诺,否則無(wú)法驗(yàn)證通過(guò)
//--use-libraries:如果依賴了靜態(tài)庫(kù)就需要加上該選項(xiàng)
pod spec lint --allow-warnings --use-libraries
或
pod lib lint pod_test.podspec --allow-warnings --use-libraries
//如果失敗歪脏,報(bào)超時(shí)疑俭,可多試幾次
三粮呢、將本地的podspec文件推送到遠(yuǎn)程索引庫(kù)中。
1.創(chuàng)建一個(gè)空的git倉(cāng)庫(kù)用于存放podSpec钞艇。如第一步啄寡。這里起名為SBAIPracticeSpec。git地址為:https://github.com/Manchitor/SBAIPracticeSpec.git
2.本地創(chuàng)建一個(gè)存放podspec的目錄哩照,可隨意挺物。本文這里與SBAIPractice同級(jí)別。
3.本地目錄關(guān)聯(lián)git飘弧,cd到SBAIPracticeSpec下后一次執(zhí)行如下命令识藤,注意替換git地址。
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Manchitor/SBAIPracticeSpec.git
git push -u origin main
4.創(chuàng)建本地索引
pod repo add SBAIPracticeSpec https://github.com/Manchitor/SBAIPracticeSpec.git
那么在路徑~/.cocoapods/repos下就會(huì)有SBAIPracticeSpec本地倉(cāng)庫(kù)次伶。
5.將索引push到遠(yuǎn)程索引倉(cāng)庫(kù)
到SBAIPractice.podspec所在的目錄下痴昧。
pod repo push SBAIPracticeSpec SBAIPractice.podspec --allow-warnings --use-libraries
push成功會(huì)打印"Adding the spec to the `mySpecs’ repo”。
之后mySpecs本地倉(cāng)庫(kù)里面多了pod_test庫(kù)的索引(也就是pod_test.podspec)冠王,同時(shí)會(huì)push同步到https://github.com/Manchitor/SBAIPracticeSpec.git
如下圖
回到本地目錄SBAIPracticeSpec 下赶撰。pull一下。
本地目錄如下圖:
6.試試效果
pod search ’SBAIPractice’
出現(xiàn)如下圖:
到現(xiàn)在已經(jīng)完成柱彻,
四豪娜、試試
隨便找一個(gè)工程,修改podfile
終端執(zhí)行pod install
回到項(xiàng)目會(huì)發(fā)現(xiàn) 已經(jīng)引入了哟楷。
注:下一章瘤载,講述為私有庫(kù)添加第三方及創(chuàng)建代碼文件。