cocoapods的安裝和使用參考:
https://www.jianshu.com/p/b656c3c59af5
如果要讓自己的工程能夠被引入,比如其他人的ipa只需要一句配置就能導入你的ios的sdk工程,那么首先,你的工程要具有被cocoapods引用的特性,需要將工程放到github上,並添加cocoapods能識別的spec文件,參考:
https://www.jianshu.com/p/f146fa5358d5?mType=Group (如何使用Cocoapods管理自己github上的項目,並讓其支持pod)
遇到的問題:
(1)Unable to find a pod with name, author, summary, or description matching:
解決: https://blog.csdn.net/huang512715681/article/details/51885361
command: rm ~/Library/Cashes/Cocoapods/search_index.json
(2)高版本mac報錯:MAC /usr/bin/目錄下 Operation not permitted的解決
解決:https://blog.csdn.net/yemao_guyue/article/details/80575532
command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(3) pod setup失敗或者太慢
解決:http://www.cocoachina.com/bbs/read.php?tid-193398.html
再加一點:我本地使用git clone 下我fork的,還是很慢,最后決定去一台網絡比較好的linux克隆,克隆好以后,修改了.git文件夾的名字問git_bak,並壓縮成git_bak.tar,然后復制到mac上,放到~/.cocoapods下的repo的master下(如果路徑不存在,就創建一個),然后在master目錄下執行以下動作:
tar -xvf git_bak.tar
mv git_bak .git
git checkout .
最后刪掉git_bak.tar
再執行pod setup ,很快就好了
(4)gem source --add https://ruby.taobao.org/ 失敗
解決:我沒有使用淘寶的鏡像,因為一直報404找不到,也嘗試過其他鏡像,也失敗了,所以我使用了默認鏡像。
(5)在執行git trunk push 時報錯:‘You need to register a session first’
解決:https://blog.csdn.net/Yj_sail/article/details/52363920
比如:pod trunk register test@163.com 'test' --description='my pro' ,然后你寫的郵箱會收到郵件(我的被歸類到垃圾郵箱了,你的也可能會,不要一位自己沒收到,找找看),然后按照說明,打開他給的鏈接,就可以了,然后再執行下git truck push ,你的gitHub倉庫代碼配置CocoPods支持就完成了。
(6)Podfile中導入指定庫的方式:
(6.1)導致指定版本:pod ‘庫名’, ‘版本’ 比如: pod ‘afnetworking’ , '~2.3.1'
(6.2)導入最新版本:pod ‘庫名’, : 引入庫,什么版本都可以(一般就是最新版本了) 比如: pod 'afnetworking'
所以,pod更新的時候是根據podspec中的tag來查找源文件的,所以我們在上傳sdk到github后還需要標記tag,tag必須跟podspec定義的一樣。
然后,這步很重要,給你的項目提交版本號標簽,別人使用你的pods時,Trunk找的就是你的標簽。
(7) pod update 指定庫 :
pod update 庫名 ,比如pod update MJRefresh
(8)CocoaPods 執行pod install /pod update 慢的問題:
參考:https://www.cnblogs.com/yiqiedejuanlian/p/3698788.html
command:
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
(9) pod update 自己的庫 發現沒有更新版本號
場景: 我在其他app工程的podfile中寫的引入我的庫是: pod ‘my_framework’ 意味這當我執行pod update的時候,肯定是可以拿到my_framework的最新版本的,但是我分明修改了my_framework的版本號,並且提交了代碼,但是我執行pod update 沒有拿到最新版本,還是上一個版本。
解決: 原來是修改版本號以后,忘記發布到cocoapod的管理了,所以需要在my_framework工程下執行:pod trunk push
說明:如果代碼庫里只有framework,比如只有mytest.framework,這是podspecs文件中的s.source_files的的值類似如下:
s.source_files='my.framework/**/*'
(11)ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/lebo123/LBLelinkKit.git /var/folders/nz/_6d9dzs17fl29_lh1n91md9r0000gp/T/d20180829-41657-tzjl49 --template= --single-branch --depth 1 --branch 1.0.4
是因為我的podspec文件中的這一行:
s.source = { :git => "https://github.com/lebo123/LBLelinkKit.git", :tag => "#{s.version}" }
可以看出,版本號和tag是強相關的,所以修改了版本號就要添加一個tag,比如修改了版本號為‘1.0.2’,就要推 ‘1.0.2’的tag到git上,如果不想綁定兩個的關系,
把:tag => "#{s.version}" 拿掉,不過,拿掉的話,在執行pod trunk push的時候會有告警“source:Git source should specify a tag”,不過可以添加 --allow-warnings來忽略告警,即
pod push trunk --allow-warnings
(12) Unable to accept duplicat entry for :test(1.0.4)
說明:已經發布的版本,不能重復發布,必須修改版本號以后在發布。
(13)CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
解決:https://www.cnblogs.com/yajunLi/p/6386239.html
按照說明,執行pod repo update --verbose
最后,我的LBLelinkKit工程如下:
其中的LBLelinkKit.podspec的內容如下:
Pod::Spec.new do |s|
s.name = "LBLelinkKit"
s.version = "1.0.4"
s.summary = "lebo ios framework LBLelinkKit"
s.homepage = "https://github.com/lebo123/LBLelinkKit"
s.license = "MIT"
s.authors = { "lebo123" => "cm@hpplay.cn" }
s.platform = :ios, "5.0"
s.source = { :git => "https://github.com/lebo123/LBLelinkKit.git", :tag => "#{s.version}" }
s.source_files ='LBLelinkKit.framework/**/*'
s.requires_arc = true
end
有一個test_app,要引用我的LBLelinkKit。要怎么做呢?
test_app:
(1)在Podfile中添加:
pod 'LBLelinkKit'
(2) 首次的話執行pod install ,如果是后期更新版本的話,執行pod update
LBLelinkKit:
(1)如果有新版本要發布,需要修改版本號,不能只修改代碼,重復發布相同的版本,並提交版本修改的代碼
(2)然后執行pod trunk push 到cocoapods上管理
如果LBLelinkKit上有版本發布,test_app只要執行pod update就可以拿到最新版本了。
參考文檔:
cocopods使用總結: https://www.jianshu.com/p/7d0ad4cde012
cocoapods醒目添加trunk支持問題匯總:
https://www.jianshu.com/p/64e30843ff28?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation