? 可以參考文章:
使用CocoaPods創(chuàng)建私有Spec Repo管理項(xiàng)目公共組件1
使用CocoaPods創(chuàng)建私有Spec Repo管理項(xiàng)目公共組件2
? pod lib create FJTest1
? 選ObjC
? Yes
? None
? No
? VK
? pod lib create HJPodTestLib
? jdeMacBook-Pro:PodSpecRepo j$ pod lib create HJPodTestLib
Cloning [https://github.com/CocoaPods/pod-template.git](https://github.com/CocoaPods/pod-template.git%60) into HJPodTestLib.
Configuring HJPodTestLib template.
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
( hold cmd and double click links to open in a browser. )
What language do you want to use?? [ Swift / ObjC ]
ObjC
Would you like to include a demo application with your library? [ Yes / No ]
No
Which testing frameworks will you use? [ Specta / Kiwi / None ]
None
Would you like to do view based testing? [ Yes / No ]
No
What is your class prefix?
HJ
? 修改FJTest1.podspec
? s.version = '1.0.0' 該值一定與tag值一樣
? s.summary
? s.description 描述稍微長點(diǎn)
? s.homepage 對應(yīng)的git倉庫主頁 eg:http://git.xxxxx.com/iOS/StaticLibrary/VKNetModule
? s.source 對應(yīng)的git倉庫地址 eg:http://Evan@git.xxxxx.com/iOS/StaticLibrary/VKNetModule.git
? s.source_files 表示通過pod install下載下來的文件存放路徑 source****文件夾路徑不能隨便地修改,必須是對應(yīng)的相對路徑
? s.dependency 表示當(dāng)前組件依賴的庫 ,當(dāng)你執(zhí)行pod install會自動把依賴的庫下載到本地
? 微信文章的配置如下:
? 4、編寫podspec文件,我里面標(biāo)注要修改的地方一定要修改下不要用默認(rèn)的,不然第5不會出警告。
Pod::Spec.new do |s|
s.name = 'HJPodTestLib'
s.version = '0.1.0'
s.summary = 'HJPodTestLib.' #這里要修改下
s.description = <<-DESC
description of the pod here. #這里也要修改下
DESC
s.homepage = 'https://github.com/OldGhost366/HJPodTestLib'
s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'OldGhost366' => 'oldghost007@163.com' }
s.source = { :git => 'https://github.com/OldGhost366/HJPodTestLib.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'HJPodTestLib/Classes/*/'
end
? 給組件設(shè)置tag
? git tag -a 1.0.0 -m'1.0.0版本測試組件'
? 查看tag命令 git tag
? 第一次創(chuàng)建時,需要設(shè)置遠(yuǎn)端remote
? git remote 查看遠(yuǎn)程庫簡稱 無簡稱不顯示
? git remote -v 查看遠(yuǎn)程庫url全稱 ,有簡稱也顯示,全部顯示
? git remote add [shortName] [url]
? 或者如上面微信文章所言:
? 2、在遠(yuǎn)程git服務(wù)器創(chuàng)建組件倉庫,并且和本地關(guān)聯(lián)
git add .
git commit -s -m "Initial Commit of Library"
git remote add origin https://github.com/OldGhost366/HJPodTestLib.git
git push origin master
3、創(chuàng)建tag,因?yàn)閜odspec文件中獲取Git版本控制的項(xiàng)目還需要tag號,所以我們要打上一個tag,這一步一定不要忘記 不然第5步就會說找不到版本。
git tag -m "第一版" 0.1.0
git push --tags
? 提交本地tag前先拉取。
? git pull [url簡稱] [分支簡稱] 如:git pull pb master
? 最好使用默認(rèn)的 簡稱 origin 因?yàn)閛rigin很多地方都可以省略
? git pull [分支簡稱]
? 提交到遠(yuǎn)程。
? 提交代碼:最后一步是git push -u url簡稱] [分支簡稱] 如: git push pb master
? git add . 暫存起來
? git commit -m "add README" 提交一定要寫注釋,否則不讓提交
? git push -u origin master
? 提交tag標(biāo)簽: git push [url簡稱] --tags 如:git push pb --tags
? 為了能把標(biāo)簽同步到遠(yuǎn)程服務(wù)器,我們可以這樣做:
默認(rèn)情況下,git push并不會把tag標(biāo)簽傳送到遠(yuǎn)端服務(wù)器上,只有通過顯式命令才能分享標(biāo)簽到遠(yuǎn)端倉庫。
1.push單個tag,命令格式為:git push origin [tagname]
例如:
git push origin v1.0 #將本地v1.0的tag推送到遠(yuǎn)端服務(wù)器
2.push所有tag,命令格式為:git push [origin] --tags
例如:
git push --tags
或
git push origin --tags
? pod repo:查看本地repo索引庫列表
? 也可以使用pod repo list命令查看
? 先添加我們的本地私有索引庫(這是我們第一次在本地添加索引庫)
? pod repo add [私有索引庫名字] "索引庫對應(yīng)的git地址" 添加repo
? pod repo remove xxx 刪除 我們自己的索引庫
? # pod repo add [Private Repo Name] [Your GitHub HTTPS clone URL]
$ pod repo add HJSpecs https://github.com/OldGhost366/HJSpecs.git
? 上面這句話的微信文章寫得有誤
? 刪除本地索引庫:pod repo remove VKHouseModule
? 回歸本地的組件庫:執(zhí)行代碼檢查
? pod spec lint 遠(yuǎn)端檢查spec文件是否合法,是否符合加入索引庫的邏輯標(biāo)準(zhǔn)
? 微信文章所言:5、驗(yàn)證 pod lib lint,ERROR和WARMING都不能有,不然不能提交。
jdeMacBook-Pro:HJPodTestLib j$ pod lib lint
-> HJPodTestLib (0.1.0)
HJPodTestLib passed validation.
? 關(guān)鍵一步,提交我的podspec到我們的私有索引庫
? pod repo push VKSpecs FJTest1.podspec
? 6、提交podspec到私有spec repo
這個時候需要,必須前面驗(yàn)證通過,不然提交會失敗,因?yàn)樘峤贿^程先會進(jìn)行驗(yàn)證。
執(zhí)行下面命令后CocoasPod自動會將podspec到本地和遠(yuǎn)程spec repo Git倉庫。我們這時候可以在Git遠(yuǎn)程倉庫可以看到這個podspec文件了。
pod repo push HJSpecs HJPodTestLib.podspec()
? 集成測試:
? pod search HJPodTestLib
-> HJPodTestLib (0.1.0)
HJPodTestLib.
pod 'HJPodTestLib', '~> 0.1.0'
Versions: 0.1.0 [HJSpecs repo]
(END)
? 如果找不到時,可以清除一下索引庫緩存 rm -rf ~/Library/Caches/CocoaPods/search_index.json
? 搜索到了之后,按q可以退出
? 如果需要刪除這條索引,可以在遠(yuǎn)端網(wǎng)址上刪除對應(yīng)文件夾下的podspec。然后本地pod repo update VKSpeces_iOS(索引庫名稱)
?
? 2、創(chuàng)建項(xiàng)目測試
pod init
然后我們編輯Podfile文件
target 'PodTest' do
platform :ios, '8.0'
pod 'HJPodTestLib', '~> 0.1.0'
pod 'AFNetworking'
end
執(zhí)行pod install
[!] Unable to find a specification for HJPodTestLib
? 測試失敗為什么?
? 最終解決辦法在Podfile里面增加source指定,兩個都要添加
增加下面兩個source這樣pod install就不會出問題了
source 'https://github.com/OldGhost366/HJSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
target 'PodTest' do
platform :ios, '8.0'
pod 'HJPodTestLib', '~> 0.1.0'
pod 'AFNetworking'
end
? 其他命令
? Control C 取消執(zhí)行當(dāng)前命令
? pwd 查看當(dāng)前路徑
? cd .. 回到上一級路徑
? open /. 打開file的文件夾