使用Cocoapods使用的錯(cuò)誤
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
同級的文件夾, 直接寫文件夾名稱即可, 如:
s.source_files = "LZTool"
如果有多級目錄, 一定要逐級添加. 這里也可以這么寫:
s.source_files = "LZTool/*.{h,m}"
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
版本號不一致導(dǎo)致, 修改為一樣即可!
4. 加載xib問題
如果通過cocoapods下載的類庫中含有Xib文件, 使用原來的方式初始化就不起作用了:
[[[NSBundle mainBundle] loadNibNamed:@"xibName" owner:self options:nil] lastObject];
[self.collectionView registerNib:[UINib nibWithNibName:@"xibName" bundle:nil] forCellWithReuseIdentifier:@"ZLCollectionCell"];
改為:
#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. 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)目, 編譯一下也會報(bào)這個(gè)錯(cuò). 是因?yàn)槲倚薷牧吮镜匚募械倪@個(gè)文件的路徑, 項(xiàng)目中引用的還是原先的路徑, 打開左側(cè)文件列表, 可以發(fā)現(xiàn)這個(gè)文件是紅色的, 刪除引用, 重新添加, 然后到你的github上面, 重新添加一個(gè)release
版本, 再重新執(zhí)行指令即可驗(yàn)證通過.
6: 新建的GitHub倉庫沒有選擇許可證纵东。沒法,只能刪了重新建悦荒。
7: 沒有建demo工程并上傳到GitHub救鲤。只傳了Class文件洋幻,這個(gè)時(shí)候驗(yàn)證podspec是通不過的。
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use --verbose` for more information.
8: swift版本不對
[!] The validator for Swift projects uses Swift 2.3 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 3.0, run:
`echo "3.0" > .swift-version`.
使用echo "3.0" > .swift-version
命令即可搁料。
9: podspec文件配置不對
需要注意的是s.source_files
參數(shù)面徽,如果配置為s.source_files = '/*.{h,m}’
腻要,會報(bào)錯(cuò):
- ERROR | File Patterns: File patterns must be relative and cannot start with a slash (source_files).
其它可能的報(bào)錯(cuò):
- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.
10: 如果依賴了其它CocoaPods第三方庫
請使用s.dependency
配置复罐,如 s.dependency "SDWebImage", "~> 3.7.1"
Pod::Spec.new do |s|
s.name = 'XLPhotoBrowser'
s.version = '1.0.2'
s.summary = 'a component of photo browser on iOS'
s.homepage = 'https://github.com/xiaoL0204/XLPhotoBrowser'
s.description = <<-DESC
It is a component for ios photo browser,written by Objective-C.
DESC
s.license = 'MIT'
s.authors = {'xiaoL0204' => 'xiaol0204@qq.com'}
s.platform = :ios, '6.0'
s.source = {:git => 'https://github.com/xiaoL0204/XLPhotoBrowser.git', :tag => s.version}
s.source_files = 'XLPhotoBrowser/**/*.{h,m}','Pods/**/*.{h,m}'
s.requires_arc = true
end
11: 忘記打tag
Validating podspec
-> XLPhotoBrowser (1.0.0)
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /Applications/Xcode.app/Contents/Developer/usr/bin/git clone https://github.com/xiaoL0204/XLPhotoBrowser.git /var/folders/w1/95fypdq96l92t55frcn0yhyh0000gn/T/d20161206-1790-put1kd --template= --single-branch --depth 1 --branch 1.0.0
Cloning into '/var/folders/w1/95fypdq96l92t55frcn0yhyh0000gn/T/d20161206-1790-put1kd'...
warning: Could not find remote branch 1.0.0 to clone.
fatal: Remote branch 1.0.0 not found in upstream origin
) during validation.
[!] The spec did not pass validation, due to 1 error.
12: 找不到自己上傳的框架
[!] Unable to find a pod with name, author, summary, or description matching `ZXZTools`
1: 執(zhí)行
pod setup
其實(shí)在你安裝CocoaPods
執(zhí)行pod install
時(shí),系統(tǒng)會默認(rèn)操作pod setup
雄家,然而由于中國強(qiáng)大的墻可能會pod setup不成功效诅。這時(shí)就需要手動執(zhí)行pod setup指令,如下: 終端輸入:pod setup
會出現(xiàn)Setting up CocoaPods master repo
,稍等幾十秒乱投,最底下會輸出Setup completed
咽笼。說明執(zhí)行pod setup
成功。
如果pod search
操作還是搜索失敗戚炫,如下:
終端輸入:pod search AFNetworking
2: 刪除
~/Library/Caches/CocoaPods
目錄下的search_index.json
文件
pod setup
成功后剑刑,依然不能pod search
,是因?yàn)橹澳銏?zhí)行pod search
生成了search_index.json
双肤,此時(shí)需要?jiǎng)h掉施掏。
終端輸入:rm ~/Library/Caches/CocoaPods/search_index.json
終端輸入:pod search afnetworking
(不區(qū)分大小寫)
輸出:Creating search index for spec repo ‘master’.. Done!
,稍等片刻······就會出現(xiàn)所有帶有afnetworking
字段的類庫茅糜。