這里先給出簡單使用私有庫的教程鏈接:
CocoaPods三重奏(二) 之 組件化開發(fā)
Specs satisfying the XXX
dependency were found, but they required a higher minimum deployment target
原因是“XXX”需要需要一個(gè)更高的最低部署目標(biāo)(就是podspec文件中依賴的庫的最低部署版本)
把工程部署版本改為 依賴庫的最低版本
include of non-modular header inside framework module
背景:
當(dāng)制作自己的pod時(shí),我的代碼依賴 MBProgressHUD第三方庫惋增,pod spec lint驗(yàn)證過程一直出這個(gè)錯(cuò)誤
解決辦法:
1.buldsetting 中設(shè)置 Allow Non-modular Includes In Framework Modules 為 YES
但是對我無用
2.將#import "**.h" 第三方庫寫在 .m文件中拄氯,而不是放在.h文件中即可
e.g.:
我的文件 UIView+Hint
將 #import "MBProgressHUD.h" 這行代碼放在 UIView+Hint.m文件中
pod lib lint 和 pod spec lint 命令的區(qū)別
pod lib lint是只從本地驗(yàn)證你的pod能否通過驗(yàn)證
pod spec lint是從本地和遠(yuǎn)程驗(yàn)證你的pod能否通過驗(yàn)證
我一般都是直接使用pod spec lint去驗(yàn)證pod有沒有問題
私有pod的驗(yàn)證
使用pod spec lint去驗(yàn)證私有庫能否通過驗(yàn)證時(shí)應(yīng)該,應(yīng)該要添加--sources選項(xiàng),不然會(huì)出現(xiàn)找不到repo的錯(cuò)誤
pod spec lint --sources='私有倉庫repo地址,https://github.com/CocoaPods/Specs'
3.subspec
為了讓自己的Pod被導(dǎo)入時(shí)顯示出良好的文件層劃分,subspec是必須的菩鲜。
若subspec要依賴其它的subspec,則subspec的dependency后面接的不是目錄路徑惦积,而是specA/specB這種spec關(guān)系
私有庫引用私有庫的問題
在私有庫引用了私有庫的情況下接校,在驗(yàn)證和推送私有庫的情況下都要加上所有的資源地址,不然pod會(huì)默認(rèn)從官方repo查詢狮崩。
pod spec lint --sources='私有倉庫repo地址,https://github.com/CocoaPods/Specs'
pod repo push 本地repo名 podspec名 --sources='私有倉庫repo地址,https://github.com/CocoaPods/Specs'
5.引用自己或第三方的framework或.a文件時(shí)
在podsepc中應(yīng)該這樣寫:
s.ios.vendored_frameworks = "xxx//.framework"
s.ios.vendored_libraries = "xxx//.a”
便捷地開發(fā)本地私有庫
Cocoapods就提供了一個(gè)開發(fā)模式,其實(shí)操作起來也是非常簡單的事情蛛勉,就是將所謂的引用路徑修改成本地路徑即可。就是講Podfile中的pod '庫名', :path => '本地路徑'即可睦柴。這樣在通常的修改代碼中是不需要執(zhí)行pod update的诽凌,但是對于如果修改了目錄結(jié)構(gòu)(添加、刪除或者移動(dòng)文件文件)或者是修改了Podspec文件的配置的話坦敌,最好是運(yùn)行一下pod update的命令侣诵。普通修改代碼的情況下就不需要運(yùn)行pod update命令和打tag了。
pod 'iOS-Test', :path => '../iOS-Test’
私有庫中添加資源(圖片狱窘、音視頻等)
方法共有三種:
第一種
spec.resources = ["Images/.png", "Sounds/"]
但是這些資源會(huì)在打包的時(shí)候直接拷貝的app的Bundle中杜顺,這樣說不定會(huì)和其它資源產(chǎn)生命名沖突
第二種
spec.resource = "Resources/MYLibrary.bundle"
把資源都放在bundle中,然后打包時(shí)候這個(gè)bundle會(huì)直接拷貝進(jìn)app的mainBundle中蘸炸。使用的時(shí)候在mainBundle中查找這個(gè)bundle然后再搜索具體資源
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"JZShare" withExtension:@"bundle"];
NSBundle bundle = [NSBundle bundleWithURL:bundleURL];
UIImage img = [UIImage imageNamed:icon inBundle:bundle compatibleWithTraitCollection:nil];
第三種
spec.resource_bundles = {
'MyLibrary' => ['Resources/.png'],
'OtherResources' => ['OtherResources/.png']
}
這種方法利用 framework 的命名空間躬络,有效防止了資源沖突。
使用方法是先拿到最外面的 bundle搭儒,然后再去找下面指定名字 的 bundle 對象穷当,再搜索具體資源
NSBundle *bundle = [NSBundle bundleForClass:[MYSomeClass class]];
NSURL *bundleURL = [bundle URLForResource:@"MyLibrary" withExtension:@"bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithURL: bundleURL];
UIImage *img = [UIImage imageNamed:icon inBundle:bundle compatibleWithTraitCollection:nil];
如果私有庫添加了靜態(tài)庫或者dependency用了靜態(tài)庫
那么執(zhí)行pod lib lint還有pod spec lint時(shí)候需要加上—user-libraries選項(xiàng)
否則會(huì)出現(xiàn)'The 'Pods' target has transitive dependencies錯(cuò)誤
如果私有庫只引用其他庫的subspec
只需要依賴想依賴的subspec,不用管主spec(因?yàn)橐蕾噑ubspec必然要依賴主spec)
私有庫已經(jīng)通過驗(yàn)證并傳到私有repo也能通過pod search淹禾,但是就是pod install失敗馁菜。
這時(shí)候只要執(zhí)行pod update 然后去喝杯水就好了。铃岔。汪疮。(前提是你把官方源換成國內(nèi)的,不然從github上更新官方repo的速度你懂的德撬。 更換官方源)
參考
what's the different between 'pod spec lint' and 'pod lib lint'
給Pod添加資源文件
Reject installation if a static library is used as a transitive dependency while using frameworks