寫在前面
說明:
兩個私有庫:
一個是私有代碼庫,存放需要pod封裝的代碼
一個是私有索引庫,模擬cocoapods公共索引的庫,通過這個索引找到私有代碼庫
步驟
1,根據(jù)命令提示創(chuàng)建工程
$ pod lib create CocoapodDemo
根據(jù)提問、提示創(chuàng)建一個demo工程


CocoapodDemo/CocoapodDemo/Classes中存放的就是Pod要包裝的files
2,上傳源碼
把這個工程里的代碼上傳到遠(yuǎn)程私有代碼庫(沒有的話新建一個)
3,創(chuàng)建索引庫
新建一個遠(yuǎn)程倉庫用于存放自己的私有庫的 .podspec文件(私有索引庫), 例如 git@github.com:yongqianvip/privatePodspec.git
通過下面的命令創(chuàng)建本地私有pod索引庫
$ pod repo add privatePodspec git@github.com:yongqianvip/privatePodspec.git
如果不行換用https://開頭的鏈接 ,然后再看 .cocoapods/repos/ 文件夾下就多了一個privatePodspec文件夾,里面的master文件夾是pod公共索引庫,包含成千上萬的pod索引,privatePodspec就是模擬這個公共索引庫的私有索引庫

4,功能實(shí)現(xiàn)
到這里,私有代碼庫和私有索引庫都創(chuàng)建完畢,接下來就是功能實(shí)現(xiàn),想要實(shí)現(xiàn)什么功能,把相應(yīng)的功能實(shí)現(xiàn)文件、頭文件等放入CocoapodDemo/CocoapodDemo/Classes目錄下,在Example文件夾下的工程中進(jìn)行測試,然后一并上傳到遠(yuǎn)程代碼庫

5,編輯CocoapodDemo.podspec文件
這個應(yīng)該無需過多解釋,主要配置好source和source_files,更多參數(shù)送傳送門http://guides.cocoapods.org/syntax/podspec.html

6,驗(yàn)證CocoapodDemo.podspec文件
$ pod lib lint
在CocoapodDemo.podspec文件所在目錄下執(zhí)行上面的命令,如果驗(yàn)證通過會顯示

如果有
ERROR一定要先修改錯誤,如果是可以忽略的警告加 --allow-warnings 參數(shù)
文末列出了幾個錯誤,可以參考,也歡迎補(bǔ)充。。。
7,打tag提交代碼
podspec驗(yàn)證通過之后,私有代碼庫打tag提交
$ git tag '0.0.1'
$ git push --tags
tag 要和 .podspec文件中的version一致
8,添加到本地索引庫
$ pod repo push privatePodspec CocoapodDemo.podspec
注意: 如果lint的時候添加了 --allow-warnings --use-libraries 等參數(shù)的話,push的時候也要加上

9,驗(yàn)證
$ pod search RRCLogin

如果之前步驟都成功,但是驗(yàn)證環(huán)節(jié)報(bào)錯
[!] Unable to find a pod with name, author, summary, or description matching 'RRCLogin'可能是緩存的問題,清理
cocoapod的search緩存
$ rm ~/Library/Caches/CocoaPods/search_index.json
再執(zhí)行search(清理search的緩存之后再搜索時間會有點(diǎn)兒長)
10,使用我們上傳的私有pod
在需要引用這個庫的工程的Podfile中添加
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/yongqianvip/privatePodspec.git'
這是為了告訴pod,檢索依賴的時候既要檢索公共索引庫,咱們本地的私有索引庫也要檢索
總結(jié)
這里是借助公開庫 模擬私有庫的pod封裝,我們的索引沒有推送到cocoapod遠(yuǎn)程庫,假想一下,如果我們的這兩個倉庫都是私有的,那么別人就搜不到我們的代碼,就實(shí)現(xiàn)了真正的私有pod
pod lib lint 時遇到的一些ERROR
錯誤 NO.1
Building with xcodebuild.
xcodebuild clean build -workspace /var/folders/nc/2btst88j1dn9spsydgzy94m80000gp/T/CocoaPods-Lint-20180301-68829-1lc144r-RRCLogin-Inhouse/App.xcworkspace -scheme App -configuration Release CODE_SIGN_IDENTITY=- -sdk iphonesimulator -destination id=EF5C4592-DA0A-40C4-B14A-040C9934FA86
Build settings from command line:
CODE_SIGN_IDENTITY = -
SDKROOT = iphonesimulator11.2
xcodebuild: error: Unable to find a destination matching the provided destination specifier:
{ id:EF5C4592-DA0A-40C4-B14A-040C9934FA86 }
Available destinations for the "App" scheme:
{ platform:iOS, id:3364f575ca6f4054e91f7273bbf1dfcd057a4786, name:YYQ的 iPhone }
{ platform:iOS Simulator, id:B461000D-7668-4984-969E-F4A6F2B5F822, OS:11.0.1, name:iPad (5th generation) }
{ platform:iOS Simulator, id:274C9F62-9F24-4A68-97FA-F58ACBD752D8, OS:11.2, name:iPad (5th generation) }
{ platform:iOS Simulator, id:A5594DF0-938B-4AD3-A2E4-D9DF0C462206, OS:11.2, name:iPhone 5s }
{ platform:iOS Simulator, id:0443319F-6EF8-49CF-A93F-0EACA18B1BAB, OS:11.2, name:iPhone 6 }
{ platform:iOS Simulator, id:6B8AB42A-32BB-476C-B93A-796D0A5F0D1B, OS:11.2, name:iPhone 6 Plus }
{ platform:iOS Simulator, id:25F0DBDA-4F38-4004-AA01-8250302B466B, OS:11.2, name:iPhone 6s }
{ platform:iOS Simulator, id:177042D1-C48E-4F0E-A285-F155B7D2A608, OS:11.2, name:iPhone 6s Plus }
{ platform:iOS Simulator, id:FA65D37F-74A6-40C9-817E-9C929D660348, OS:11.2, name:iPhone 7 }
{ platform:iOS Simulator, id:2DD23829-DC3C-49B5-822E-D859B0B03E5C, OS:11.2, name:iPhone 7 Plus }
{ platform:iOS Simulator, id:A24F0CBF-55B5-46B2-9B4A-36FFD6C4E7D1, OS:11.2, name:iPhone 8 }
{ platform:iOS Simulator, id:E84B2668-BC88-42FA-8A4E-FF731AA52383, OS:11.2, name:iPhone 8 Plus }
{ platform:iOS Simulator, id:770C7323-027A-45EF-87E4-C07DECA5B116, OS:11.2, name:iPhone SE }
{ platform:iOS Simulator, id:1368D6CC-FE26-4403-BD4F-B6FDD6AFE47F, OS:11.2, name:iPhone X }
Ineligible destinations for the "App" scheme:
{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Generic iOS Device }
{ platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Generic iOS Simulator Device }
Testing with xcodebuild.
-> RRCLogin-Inhouse (0.1.0)
- WARN | url: There was a problem validating the URL http://gitlab.renrenche.com/DQD_IOS_module/RRCInhouseLogin.
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
- NOTE | [iOS] xcodebuild: xcodebuild: error: Unable to find a destination matching the provided destination specifier:
[!] RRCLogin-Inhouse did not pass validation, due to 1 error and 1 warning.
You can use the `--no-clean` option to inspect any issue.
這個錯誤目前還不清楚原因,初步推測是環(huán)境變量的問題,為了解決這個錯誤,我換了臺電腦、我換了臺電腦、我換了臺電腦
錯誤 NO.2
- ERROR | xcodebuild: /Users/YYQ/Library/Developer/Xcode/DerivedData/App-aajotsmzgxneapbmwyfqevaamvpu/Build/Products/Release-iphonesimulator/RRCLogin-Inhouse/RRCLogin_Inhouse.framework/Headers/RRCPayNetworkHttpResponse.h:10:9: error: include of non-modular header inside framework module 'RRCLogin_Inhouse.RRCPayNetworkHttpResponse': '/Users/YYQ/Library/Developer/Xcode/DerivedData/App-aajotsmzgxneapbmwyfqevaamvpu/Build/Products/Release-iphonesimulator/JSONModel/JSONModel.framework/Headers/JSONModel.h' [-Werror,-Wnon-modular-include-in-framework-module]
這個錯誤是文件引用的問題,我的代碼中用到了JSONModel,引用的方式是 #import "JSONModel.h”,但是JSONModel是通過s.dependency 'JSONModel’, ‘~> 1.5.1’的方式,引入的,那么我自己的代碼中使用JSONModel就應(yīng)該是用尖括號的形式引入了
#import <JSONModel.h>這是不對的,應(yīng)該用#import <JSONModel/JSONModel.h>,否則會有下邊的錯
https://github.com/CocoaPods/CocoaPods/issues/5715
錯誤 NO.3
- ERROR | [iOS] xcodebuild: /Users/YYQ/RRC/Podmodules/RRCLogin-Inhouse/RRCLogin-Inhouse/Classes/login/GETVerificationVoiceCodeRequest.m:11:9: error: 'JSONModel.h' file not found with <angled> include; use "quotes” instead
這個錯誤是路徑的問題,我的代碼中用到了JSONModel,引用的方式是 #import <JSONModel.h>,改成#import <JSONModel/JSONModel.h> 就可以了
錯誤 NO.4
- ERROR | [iOS] unknown: Encountered an unknown error (The 'Pods-App' target has transitive dependencies that include static binaries: (/private/var/folders/m7/7t1r7_993fbgs40fppwxrsm80000gn/T/CocoaPods-Lint-20180301-60100-1meifl-Payment/Pods/openssl-ios-bitcode/lib/libcrypto.a and /private/var/folders/m7/7t1r7_993fbgs40fppwxrsm80000gn/T/CocoaPods-Lint-20180301-60100-1meifl-Payment/Pods/openssl-ios-bitcode/lib/libssl.a)) during validation.
依賴了其他庫,lint 檢查的時候添加后綴
$ pod lib lint --use-libraries