步驟流程
1.在git上創(chuàng)建新的repository,填寫name(你的庫名稱)妨退,勾選readme選項(xiàng)浓镜,選擇license;
2.將創(chuàng)建的repository clone下來换途,cd進(jìn)入該目錄下懊渡,將自己的庫文件和demo放在這個目錄下;
-
3.使用如下命令军拟,在這個目錄中創(chuàng)建.podspec文件剃执;
pod spec create xxx
xxx是你的庫名稱整個目錄結(jié)構(gòu)如下:
- 4.填寫.podspec
新創(chuàng)建的. podspec里加#的都是注釋掉的字段信息,按需填寫懈息,有些可以不填肾档;
Pod::Spec.new do |s|
s.name = "UIImageKit"
s.version = "1.0.0"
s.summary = "UIImageKit is a library of UIImage class."
s.description = <<-DESC
UIImageKit is a library of UIImage class, a simple kit.
DESC
s.homepage = "https://github.com/Kangqj/UIImageKit"
s.license = "MIT"
s.author = { "Kangqj" => "kang_qj@sina.cn" }
s.source = { :git => "https://github.com/Kangqj/UIImageKit.git", :tag => "#{s.version}" }
s.source_files = "UIImageKit/**/*"
s.platform = :ios
s.framework = "UIKit"
end
主要解釋兩個字段:
source_files:資源文件,當(dāng)前路徑就是庫路徑辫继,后面再拼接庫文件所在的文件夾怒见,
“*” 表示匹配所有文件
“*.{h,m}” 表示匹配所有以.h和.m結(jié)尾的文件
“**” 表示匹配所有子目錄
s.description:這個描述字段可以不用填寫,如果要填寫的話姑宽,需要將描述寫在
<<-DESC
xxx
DESC
之間遣耍。
- 5.將項(xiàng)目打tag,push到git上
git tag ‘1.0.0’
git push --tags
-
6.驗(yàn)證你的.podspec是否有效
pod spec lint
驗(yàn)證成功會顯示:
xxx.podspec passed validation.
-
7.注冊CocoaPods
pod trunk register xxx.podspec youremail.com ‘your name’ —verbose
完成之后的結(jié)果:
[!] Please verify the session by clicking the link in the verification email that has been sent to youremail.com
打開你的郵箱低千,會收到一封[CocoaPods] Confirm your session
的郵件配阵,點(diǎn)擊里面的鏈接,就完成了注冊過程示血。
使用命令:pod trunk me
可以檢查是否注冊成功棋傍,如果返回你注冊的信息,說明注冊成功了难审。
-
8.發(fā)布pod
pod trunk push xxx.podspec
等待瘫拣。。告喊。
Creating search index for spec repo 'master'..` Done!
成功麸拄。
- 9.驗(yàn)證是否真的成功
`pod search xxx`
能搜索出來自己的庫就說明大功告成了^_^
……Y(^_^)Y
- 10.版本更新
第一個版本上傳好了之后派昧,如果后期需要更新,不管是只更新.podspec文件拢切,還是更新工程資源文件蒂萎,此時如果進(jìn)行`pod trunk push xxx.podspec `發(fā)布的話,會提示錯誤:
[!] Unable to accept duplicate entry for: xxx
**應(yīng)該這樣做:**
1.先更新.podspec文件中的 s.version版本號;
2.然后 git tag 打和.podspec中一樣的tag淮椰,再將改動push到git上;
3.最后再pod trunk push
就可以了五慈。
更新結(jié)束,然后就可以更新你本地工程的`Podfile`文件中的版本號主穗,再執(zhí)行`pod update xxx`泻拦,就可以將剛剛上傳的版本拉下來,檢查一下更新的版本是否有問題忽媒。
***
##遇到的問題及解決方法
- 問題1 .
NOTE | [OSX] xcodebuild: UIImageKit/UIImageKit/UIImage+Generate.h:9:9: fatal error: 'UIKit/UIKit.h' file not found
> 解決:.podspec文件沒有添加下面兩個字段争拐,加上就好了
s.platform = :ios
s.framework = "UIKit"
- 問題2.
- ERROR | file patterns: The `source_files` pattern did not match any file.
> 解決:.podspec文件中的`source_files`格式填寫的不對,找不到資源文件
source_files:資源文件晦雨,當(dāng)前路徑就是庫路徑架曹,后面再拼接庫文件所在的文件夾,
“” 表示匹配所有文件
“.{h,m}” 表示匹配所有以.h和.m結(jié)尾的文件
“**” 表示匹配所有子目錄
- 問題3.
- WARN | description: The description is equal to the summary.
> 解決:這是一個警告金赦,原因是.podspec中的description字段和summary字段內(nèi)容填寫的一樣音瓷,改成不一樣的就沒有了。
- 問題4.
在執(zhí)行
`pod trunk push UIImageKit.podspec`
命令后一只卡在
`Updating spec repo master ` 這一步夹抗,
需要等待一段時間后绳慎,會出現(xiàn)
[!] Unable to accept duplicate entry for: UIImageKit (1.0.0)
庫其實(shí)沒有傳上去,搜索不到漠烧。
> 解決:
使用命令:
pod setup
再進(jìn)行一次`pod trunk push`杏愤,如果還不行的話,可以使用命令:
pod repo update --verbose
- 問題5.
[!] Unable to find a pod with name, author, summary, or descriptionmatching `xxx`
> 解決:搜索不到你的庫已脓,使用下面的命令珊楼,一處搜索目錄的緩存文件,然后再search
rm ~/Library/Caches/CocoaPods/search_index.json
[UIImageKit](https://github.com/Kangqj/UIImageKit/tree/master/UIImageKit)