上篇文章[Cocoapods]項(xiàng)目添加Cocoapods支持主要介紹了添加Cocoapods支持的大致過程, 當(dāng)然文章看上去是一帆風(fēng)順的. 但是, 事實(shí)并不是這樣. 上篇文章篇幅過長, 就把之間遇到的一些問題, 單獨(dú)寫了出來.
1. ERROR | spec: The specification defined in `LZTool.podspec` could not be loaded.
MacBook:PodTest Artron_LQQ$ pod lib lint LZTool.podspec
-> LZTool.podspec
- ERROR | spec: The specification defined in `LZTool.podspec` could not be loaded.
[!] Invalid `LZTool.podspec` file: syntax error, unexpected tIDENTIFIER, expecting keyword_end
...<-DESC 這是一個(gè)測試文檔, 這里主要是描述類庫...
... ^
LZTool.podspec:28: syntax error, unexpected '\n', expecting '='.
# from LZTool.podspec:27
# -------------------------------------------
# # * Finally, don't worry about the indent, CocoaPods strips it!
> s.description = <<-DESC 這是一個(gè)測試文檔, 這里主要是描述類庫的功能設(shè)計(jì)初衷介紹
# DESC
# -------------------------------------------
[!] LZTool.podspec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
You can use the `--no-clean` option to inspect any issue.
MacBook:PodTest Artron_LQQ$
這個(gè)錯(cuò)誤是使用指令pod lib lint LZTool.podspec 檢查文件是否合法時(shí)發(fā)生的;
可以看出是在設(shè)置s.description 字段時(shí)發(fā)生的錯(cuò)誤, 當(dāng)時(shí)的寫法是:
s.description = <<-DESC LZTool 是一個(gè)用于保存一些常用工具類的工具 DESC
以為可以吧他們并到一行, 導(dǎo)致一直報(bào)這個(gè)錯(cuò), 后來寫成兩行, 還是報(bào)錯(cuò), 最后才試出這樣寫才對:
s.description = <<-DESC
LZTool 是一個(gè)用于保存一些常用工具類的工具
DESC
2. [iOS] file patterns: The `source_files` pattern did not match any file.
MacBook:PodTest Artron_LQQ$ pod lib lint LZTool.podspec
-> LZTool (0.0.1)
- WARN | github_sources: Github repositories should end in `.git`.
- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.
[!] LZTool did not pass validation, due to 1 error and 1 warning.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
You can use the `--no-clean` option to inspect any issue.
MacBook:PodTest Artron_LQQ$
這個(gè)錯(cuò)誤也是使用指令pod lib lint LZTool.podspec 檢查文件是否合法時(shí)發(fā)生的;
這個(gè)是在指定共享的類庫時(shí), 文件路徑不對, 也就是設(shè)置s.source_files 字段時(shí), 發(fā)生了錯(cuò)誤, 這里的路徑是相對于LZTool.podspec文件的, 如果是與LZTool.podspec同級(jí)的文件夾, 直接寫文件夾名稱即可, 如:
s.source_files = "LZTool"
這里也可以這么寫:
s.source_files = "LZTool/*.{h,m}"
如果同級(jí)文件夾內(nèi)有子文件夾梅肤,需要這么寫:
s.source_files = "LZTool/**/*.{h,m}"
這樣會(huì)加載同級(jí)文件夾內(nèi)的所有文件,包括子文件夾內(nèi)的文件步绸;
如果只需要加載某個(gè)子文件夾目錄下的文件, 一定要逐級(jí)添加.
s.source_files = "LZTool", "LZTool/obj/*.{h,m}"
如果绩聘,在某個(gè)版本的tag下報(bào)此錯(cuò)誤,更改為正確路徑后修陡,還是報(bào)此錯(cuò)誤媒抠,可嘗試新建一個(gè)新的tag;
3. fatal: Remote branch 0.0.1 not found in upstream origin
MacBook:PodTest Artron_LQQ$ pod spec lint
-> LZTool (0.0.1)
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/LQQZYY/PodTest.git /var/folders/14/95vmx0495_s5292ltvwpsc8h0000gn/T/d20170111-11240-1l3iq9n --template= --single-branch --depth 1 --branch 0.0.1
Cloning into '/var/folders/14/95vmx0495_s5292ltvwpsc8h0000gn/T/d20170111-11240-1l3iq9n'...
warning: Could not find remote branch 0.0.1 to clone.
fatal: Remote branch 0.0.1 not found in upstream origin
) during validation.
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
MacBook:PodTest Artron_LQQ$
這個(gè)是使用指令pod spec lint來檢查文件是否可用時(shí)發(fā)生的錯(cuò)誤;
這是因?yàn)樵谀阃泄艽a的庫里(這里是指github)找不到這個(gè)分支, 也就是在編輯 LZTool.podspec 時(shí), 里面的字段 s.verson, s.source 中的 tag與github創(chuàng)建的release版本號(hào)不一致導(dǎo)致, 修改為一樣即可!
這里還有另外一個(gè)解決方法方法二
4. 加載xib問題
PS: 這個(gè)不是我個(gè)人遇到的問題, 是在文章中看到, 這里記錄一下;
如果通過cocoapods下載的類庫中含有Xib文件, 使用原來的方式初始化就不起作用了:
[[[NSBundle mainBundle] loadNibNamed:@"xibName" owner:self options:nil] lastObject];
[self.collectionView registerNib:[UINib nibWithNibName:@"xibName" bundle:nil] forCellWithReuseIdentifier:@"ZLCollectionCell"];
應(yīng)該使用下面這種方式初始化:
#define kZLPhotoBrowserBundle [NSBundle bundleForClass:[self class]]
[[kZLPhotoBrowserBundle loadNibNamed:@"ZLPhotoActionSheet" owner:self options:nil] lastObject];
[self.collectionView registerNib:[UINib nibWithNibName:@"ZLCollectionCell" bundle:kZLPhotoBrowserBundle] forCellWithReuseIdentifier:@"ZLCollectionCell"];
這樣就能正常使用了;
5.加載圖片資源問題
PS: 這個(gè)問題我嘗試了一個(gè)demo, 直接設(shè)置了s.resources = "LZScaner/images/*.png" , 圖片也能正常顯示( 可參考我設(shè)置的podspec文件LZScaner.podspec )沒有遇到這個(gè)問題, 但是還是把這個(gè)方式記錄一下吧...
如果通過代碼"[UIImage imageNamed:@"picName"]" 去設(shè)置圖片的話官硝,則圖片資源有可能無法正常顯示, 可通過以下方式解決:
- 創(chuàng)建bundle資源目錄
command+N -> Resource -> Settings Bundle
刪除bundle攜帶的無用文件,把圖片資源添加到bundle資源內(nèi)
- 改變代碼圖片路徑
// 圖片路徑
#define kZLPhotoBrowserSrcName(file) [@"ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]
#define kZLPhotoBrowserFrameworkSrcName(file) [@"Frameworks/ZLPhotoBrowser.framework/ZLPhotoBrowser.bundle" stringByAppendingPathComponent:file]
kZLPhotoBrowserSrcName(file) 為通過copy文件夾方式獲取圖片路徑的宏
kZLPhotoBrowserFrameworkSrcName(file) 為通過cocoapods下載安裝獲取圖片路徑的宏
- 然后修改代碼中設(shè)置圖片的方式如下
UIImage *img = [UIImage imageNamed:kZLPhotoBrowserSrcName(@"img.png")]?:[UIImage imageNamed:kZLPhotoBrowserFrameworkSrcName(@"img.png")];
其podspec地址: ZLPhotoBrowser.podspec 可以參考學(xué)習(xí)!
6. trunk: getaddrinfo: nodename nor servname provided, or not known
MacBook:LZScaner Artron_LQQ$ pod trunk register 302934443@qq.com --description= 'LZScaner'
[!] There was an error registering with trunk: getaddrinfo: nodename nor servname provided, or not known
MacBook:LZScaner Artron_LQQ$
出現(xiàn)這個(gè)原因是, 我開了APN, 把APN關(guān)了, 重新啟動(dòng)一下網(wǎng)絡(luò)就好了...
7. xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information
MacBook:LZSortTool Artron_LQQ$ pod spec lint
-> LZSortTool (0.0.1)
- WARN | [iOS] license: Unable to find a license file
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
- NOTE | [iOS] xcodebuild: LZSortTool/LZSortToolDemo/LZSortToolDemo/LZSortClass/LZSortTool.m:14:9: fatal error: 'ChineseToPinyin.h' file not found
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 error and 1 warning.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
MacBook:LZSortTool Artron_LQQ$
這個(gè)是執(zhí)行 pod spec lint指令的時(shí)候產(chǎn)生的錯(cuò)誤:
這個(gè)錯(cuò)誤從- NOTE可以看出, 是項(xiàng)目中的這個(gè)文件ChineseToPinyin.h找不到, 回到項(xiàng)目, 編譯一下也會(huì)報(bào)這個(gè)錯(cuò). 是因?yàn)槲倚薷牧吮镜匚募械倪@個(gè)文件的路徑, 項(xiàng)目中引用的還是原先的路徑, 打開左側(cè)文件列表, 可以發(fā)現(xiàn)這個(gè)文件是紅色的, 刪除引用, 重新添加, 然后到你的github上面, 重新添加一個(gè)release版本, 再重新執(zhí)行指令即可驗(yàn)證通過.
8. 驗(yàn)證成功后搜索不到新加的支持庫
如果在制作支持庫的過程中沒有錯(cuò)誤, 或者最好添加庫驗(yàn)證通過, 即出現(xiàn)下面這個(gè)界面:
在使用
pod search LZTool
的時(shí)候, 搜索不到這個(gè)庫, 或者在使用時(shí)找不到這個(gè)庫, 可以使用下面的指令來清理一下緩存:
rm ~/Library/Caches/CocoaPods/search_index.json
然后再去使用, 基本就可以了.
9. ERROR | name: The name of the spec should match the name of the file.
LQQ-MacBook-Pro:LQWebViewSwift LQiqiang$ pod lib lint LQWebViewSwift.podspec
-> LQWebView-Swift (1.0)
- ERROR | name: The name of the spec should match the name of the file.
- ERROR | [iOS] unknown: Encountered an unknown error (No podspec found for `LQWebView-Swift` in `/Users/LiuQiqiang/Desktop/SourcesTree/Cocoapods/LQWebViewSwift`) during validation.
[!] LQWebView-Swift did not pass validation, due to 2 errors.
You can use the `--no-clean` option to inspect any issue.
LQQ-MacBook-Pro:
出現(xiàn)這個(gè)錯(cuò)誤是因?yàn)槎掏桑业?strong>podspec 文件名稱和里面設(shè)置的 ** s.source_files** 和 s.name 不一致導(dǎo)致的氢架,修改為一致的即可!
10. [!] You (youremail@qq.com) are not allowed to push new versions for this pod. The owners of this pod are ohtersemail@qq.com.
[!] You (youremail@qq.com) are not allowed to push new versions for this pod. The owners of this pod are ohtersemail@qq.com.
這是在執(zhí)行 pod trunk push LQKit.podspec --allow-warnings時(shí)報(bào)的錯(cuò)誤朋魔,這是倉庫名稱重復(fù)了达箍,就修改了一個(gè),再次提交铺厨,成功!