最近做一個SDK,需要用cocoapods發(fā)布,下面總結(jié)下發(fā)布流程,及一些坑
首先梳理下大致流程
- 1.將代碼提交到倉庫
- 2.注冊trunk賬戶
- 3.創(chuàng)建podspec文件
- 4.提交代碼
首先,將我們的pod更新到最新版本
sudo gem install cocoapods
更新的時候可能報錯,下面是錯誤信息
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
解決辦法
sudo gem install -n /usr/local/bin cocoapods
pod更新完之后,開始我們的提交
1.將代碼提交到倉庫
注意,任意倉庫都行,不一定非要github
這一部分不做細說,git用法自行百度,下面是一些注意事項
- git上創(chuàng)建項目的時候最好帶上
.gitignore,README.me,LICENSE文件,這樣方便后續(xù)使用 - 給要發(fā)布的版本加tag,pod在拉取代碼的時候是根據(jù)tag的,也可以根據(jù)commit拉取,但是commit太長,另外可以將tag和version設(shè)置相同,方便管理
下面是簡單的提交代碼和提交tag的命令,如果出錯了,百度git用法
git add .
git commit -m “version 1.0.0”
git push origin master
git tag '1.0.0'
git push --tags
git tag //查看tag
git tag -d '1.0.0' // 刪除指定標簽
2.注冊trunk賬戶
想要發(fā)布代碼,得先注冊賬戶
pod trunk register 郵箱 '用戶名' --verbose
注冊成功后在你輸入的郵箱中會收到一封郵件, 下面是郵件內(nèi)容
Hi Miridescent,
Please confirm your registration with CocoaPods by clicking the following link:
https://trunk.cocoapods.org/sessions/verify/712c7c88
If you did not request this you do not need to take any further action.
Kind regards, the CocoaPods team
點擊郵件中網(wǎng)址,跳轉(zhuǎn)到網(wǎng)頁即注冊成功,如果不能點擊,復制粘貼到瀏覽器打開也可以
添加其他維護者(如果你的pod是由多人維護的,你也可以添加其他維護者)
pod trunk add-owner 庫名 共同維護者郵箱
3.創(chuàng)建podspec文件
命令
pod spec create test
會生成一個test.podspec文件
用編輯器打開這個文件,發(fā)現(xiàn)有許多內(nèi)容,大部分都是注釋,我們只要根據(jù)需要保留自己想要的部分即可,主要的幾個參數(shù)如下
Pod::Spec.new do |s|
s.name = "test" // 名稱
s.version = "1.0.0" // 版本
s.summary = "test pod" // 總結(jié)
s.description = 'test pod a' // 描述
s.homepage = "https://github.com/Miridescen/coco_test1" // 項目主頁
s.license = { :type => "MIT", :file => "LICENSE" } // 協(xié)議文件
s.author = { "xx" => "郵箱" } // 作者
s.platform = :ios, "8.0" // 支持的版本
s.ios.deployment_target = "8.0" // ios開發(fā)支持的版本,對應的還有tvOS、watchOS等
s.source = { :git => "https://github.com/Miridescen/coco_test1.git", :tag => s.version } 代碼地址
s.source_files = "trs_ta_sdk_test", "trs_ta_sdk.framework/**/*.{h,m,c}" // 要發(fā)布的文件
s.vendored_frameworks = 'trs_ta_sdk.framework' // 要發(fā)布的framework框架
s.public_header_files = 'trs_ta_sdk.framework/Headers/*.h' // 要顯示的頭文件
s.frameworks = "UIKit", "Foundation" // 引用的框架
s.requires_arc = true // 是否支持ARC
end
大致就是這些就可以,其中有以下幾點需要注意
- s.description要比s.summary長,否則會報警告
- WARN | description: The description is shorter than the summary.
- s.license中的標明的文件必須有對應的存在,否則會報警告
- s. source中的版本號必須在倉庫中有對應的標簽,否則會報警告,其實這里的tag參數(shù)可以用commit代替,后面接的是對應的commit值,就是
ba01464749bb73e4bc380a9301e2ce8e7bfab3f3這樣的一大長串東西
最好將s.version和tag相對應,這樣方便查找管理
- WARN | source: The version should be included in the Git tag.
- s.source_files這個路徑很重要,不要填錯了,可以用*匹配,下面是匹配規(guī)則
*表示匹配所有文件
*.{h,m}表示匹配所有以.h和.m結(jié)尾的文件
**表示匹配所有子目錄
配置好文件之后檢查podspec是否合格
pod spec lint test.podspec
如果沒有問題的話會有提示
Analyzed 1 podspec.
test.podspec passed validation.
這里有可能會出現(xiàn)一個看不懂的報錯
- ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
) during validation.
這時我們需要修改xcode的命令行工具配置
xcode->prefences->locations->command line tools,如下圖

4.提交代碼
上面的東西都準備好之后,直接
pod trunk push
成功之后會有下面的提示
--------------------------------------------------------------------------------
?? Congrats
?? xxx (1.0.0) successfully published
?? May 20th, 23:59
?? https://cocoapods.org/pods/xxx
?? Tell your friends!
--------------------------------------------------------------------------------
恭喜你,提交成功了,可以快樂的玩耍了
pod search xxx
命令可以搜索下我們剛剛提交的代碼,可能會出現(xiàn)下面的錯誤
[!] Unable to find a pod with name, author, summary, or description matching `xxx`
這是pod沒有及時的更新依賴庫,可以有下面兩種解決辦法
pod setup執(zhí)行更新
如果還不行的話先移除search_index.json文件,然后重新創(chuàng)建
rm ~/Library/Caches/CocoaPods/search_index.json
pod search xxx
這里可以放心大膽的移除,在執(zhí)行pod search xxx的時候search_index.json文件就會自動創(chuàng)建
上面就是一些總結(jié)和一些坑,有問題可以提出一起交流