一、準備工作
1、gitlab內(nèi)部建一個空的倉庫,用于托管模塊的代碼;
2、通過執(zhí)行命令pod lib create SCDataReporterLib創(chuàng)建pod倉庫模版;
二、配置podspec文件
1、主頁、git地址、版本、tag
2、其中source填寫git地址,dependency配置依賴的一些三方庫,按規(guī)范走的話version和tag保持一致,也便于后期維護;
三、 封版
代碼提交 & 關(guān)聯(lián)源
git init
git remote add origin xxx.git
git add .
git commit -m "init"
git push -u origin master
打tag
git tag '0.10'
git push --tags
四、創(chuàng)建私有spec Repo
1、執(zhí)行 pod repo add MNKitSpecs xxx索引庫地址,此時會發(fā)現(xiàn)~/.cocoapods/repos目前下生成了MNKitSpecs的文件夾以及對應(yīng)的版本
2、驗證spec
執(zhí)行pod spec lint,若驗證通過可以繼續(xù)執(zhí)行步驟3;
由于我封的庫依賴了私有庫SCBaseLib,驗證不通過,會在問題匯總中詳細描介紹;
3、推送spec
執(zhí)行pod repo push mySpecs pod_test.podspec
推送成功了在遠程倉庫是可以看到的
五、接入使用
1、配置source 'xxx.git';
2、pod 'XXXReporter', '0.2.7'
3、cd到podfile所在的目錄下,執(zhí)行pod update進行下載私有庫XXXReporter;
六、問題匯總
問題一
驗證spec報錯
原因:
默認情況cocoapods會去github的源查找,及https://github.com/CocoaPods/Specs.git,由于依賴的SCBaseLib是一個私有庫,當然找不到了。
解決方式
通過指定源的方式去查找驗證,執(zhí)行pod spec lint --verbose --use-libraries --allow-warnings --sources='xxx.git, https://github.com/CocoaPods/Specs.git';其中參數(shù)--verbose是展示詳細的信息,不需要的話可以去掉;這個參數(shù)--use-libraries很重要。
問題二
push spec失敗
原因:
和上一個是同樣的問題,push的時候也會自動進行驗證spec
解決方式
方式1:通過指定源的方式去push,執(zhí)行pod repo push SRMKitSpecs SCDataReporter.podspec --sources='xxx.git, https://github.com/CocoaPods/Specs.git' --allow-warnings --use-libraries
方式2:關(guān)閉驗證,畢竟已經(jīng)驗證過了,直接push就好了;