項(xiàng)目上線识窿,終于又有時(shí)間研究些三方的東西了,在自己鉆牛角的時(shí)候脑融,不覺(jué)間陷入了誤區(qū)喻频。在項(xiàng)目實(shí)踐過(guò)程中,跟老大也學(xué)到了很多肘迎,也感覺(jué)自己肚子有了些油水甥温,可看到GitHub上那些大牛的開(kāi)源大作,不免自卑妓布。雖入行一年姻蚓,承蒙老大看得起,交給了個(gè)帶徒弟的任務(wù)匣沼,交流中受虐與進(jìn)步同行狰挡,苦澀與暖心并進(jìn)。雖然自己師范出身释涛,可離合格的老師圆兵,真心還是有差距的,至少隊(duì)友給的反饋是:“表達(dá)能力太差枢贿,永遠(yuǎn)活在自己的思路里”。突然想到了小岳岳一句話:“雖然每天工作很累刀脏,但是我掙得少熬旨浴!”愈污,我要說(shuō)的是:“你每天那么努力耀态,忍受了那么多寂寞和痛苦,可我也沒(méi)見(jiàn)你多么優(yōu)秀霸荼ⅰ首装!”,哥懂的還是太少杭跪。好了仙逻,下面是正題:
在項(xiàng)目引入第三方SDK過(guò)程中,各種引入庫(kù)文件涧尿、各種改配置系奉,特別是更新SDK的時(shí)候,著實(shí)是件讓人頭大的事情姑廉。常在網(wǎng)上看到別人使用自動(dòng)化三方庫(kù)管理工具Cocoapods缺亮,原項(xiàng)目中一直沒(méi)敢嘗試,最近一直在研究桥言,使用中確有眼前一亮的感覺(jué)萌踱,不過(guò)中間也遇到了許多問(wèn)題葵礼,賣(mài)弄如下:
安裝流程步驟此處就不多講了,網(wǎng)上隨便搜下......
- 在使用pod 命令引入文件并鸵,在終端中會(huì)提示:
Analyzing dependencies
Downloading dependencies
Installing......
Generating Pods project
[!] From now on useProjectName.xcworkspace
.
如果使用CocoaPods組織管理三方庫(kù)之后鸳粉,就只能通過(guò)ProjectName.xcworkspace打開(kāi),如果打開(kāi)原來(lái)的工程會(huì)編譯報(bào)錯(cuò)能真。
執(zhí)行pod命令之后赁严,項(xiàng)目中會(huì)生成:ProjectName.xcworkspace、Podfile.lock粉铐、Pods等文件疼约;
CocoaPods工作原理:
CocoaPods的工作主要是通過(guò)ProjectName.xcworkspace來(lái)組織的,在打開(kāi)ProjectName.xcworkspace文件后蝙泼,發(fā)現(xiàn)Xcode會(huì)多出一個(gè)Pods工程程剥。
庫(kù)文件引入及配置:
庫(kù)文件的引入主要由Pods工程中的Pods-ProjectName-frameworks.sh腳本負(fù)責(zé),在每次編譯的時(shí)候汤踏,該腳本會(huì)幫你把預(yù)引入的所有三方庫(kù)文件打包的成ProjectName.a靜態(tài)庫(kù)文件织鲸,放在我們?cè)璛code工程中Framework文件夾下,供工程使用溪胶。
如果Podfile使用了use_frameworks!
,這是生成的是.framework的動(dòng)態(tài)庫(kù)文件搂擦。引入方式也略有不同。Resource文件:
Resource資源文件主要由Pods工程中的Pods-ProjectName-resources.sh腳本負(fù)責(zé)哗脖,在每次編譯的時(shí)候瀑踢,該腳本會(huì)幫你將所有三方庫(kù)的Resource文件copy到目標(biāo)目錄中。依賴(lài)參數(shù)設(shè)置:
在Pods工程中的的每個(gè)庫(kù)文件都有一個(gè)相應(yīng)的SDKName.xcconfig才避,在編譯時(shí)橱夭,CocoaPods就是通過(guò)這些文件來(lái)設(shè)置所有的依賴(lài)參數(shù)的,編譯后桑逝,在主工程的Pods文件夾下會(huì)生成兩個(gè)配置文件棘劣,Pods-ProjectName.debug.xcconfig、Pods-ProjectName.release.xcconfig楞遏。
使用中遇到的問(wèn)題:
1. install和update命令的配置速度問(wèn)題
在我們輸入pod install
或者pod update
之后茬暇,CocoaPods首先會(huì)去匹配本地的spec庫(kù),在確認(rèn)spec版本庫(kù)不需要更新之后橱健,才會(huì)下載相應(yīng)的庫(kù)文件而钞,這樣比較耗時(shí),有時(shí)候拘荡,以為是卡死了呢臼节。所以一般使用下面兩個(gè)命令,跳過(guò)spec版本庫(kù)更新匹配。
pod update --verbose --no-repo-update
pod install --verbose --no-repo-update
有朋友說(shuō)不加--verbose
网缝,其實(shí)加--verbose
的意義在于可以輸出更詳細(xì)的配置過(guò)程 debug信息巨税,在書(shū)寫(xiě)時(shí)位置也可以換,跳過(guò)spec版本庫(kù)更新匹配的重點(diǎn)是--no-repo-update粉臊,比如:
pod install --no-repo-update --verbose // 不更新草添,并打印出詳細(xì)過(guò)程信息
2. The dependency ****
is not used in any concrete target.
[!] The dependency UMengAnalytics-NO-IDFA
is not used in any concrete target.
這個(gè)提示是因?yàn)椋琧ocoapods升級(jí)為1.0以后扼仲,Podfile文件書(shū)寫(xiě)格式的問(wèn)題远寸,
1.0之前:
platform :ios
pod 'UMengAnalytics-NO-IDFA’
pod 'MBProgressHUD', '~> 0.9.2'
pod 'FMDB'
pod 'SDWebImage', '~> 3.7.3'
pod 'IQKeyboardManager', '~> 3.2.4'
pod 'MJRefresh', '~> 2.3.2'
pod 'MJExtension', '~> 0.2.0'
1.0之后:
platform :ios,’7.0’
target ‘ProjectName’ do #ProjectName工程名字
pod 'MBProgressHUD', '~> 0.9.2'
pod 'FMDB'
pod 'SDWebImage', '~> 3.7.3'
pod 'IQKeyboardManager', '~> 3.2.4'
pod 'MJRefresh', '~> 2.3.2'
pod 'MJExtension', '~> 0.2.0'
pod 'UMengAnalytics-NO-IDFA’
end
?波浪線**~ > ** 含義:從指定版本到倒數(shù)第二位版本號(hào)升1為止,比如 ‘~> 0.3.7’所指的版本區(qū)間為[0.3.7, 0.4.0)屠凶,即>=版本0.3.7驰后,<版本0.4.0,詳見(jiàn)guides.cocoapods.org
3. Unable to satisfy the following requirements: - ***
required by Podfile
這種提示主要是因?yàn)橐砑拥念?lèi)庫(kù)有最新版本矗愧,而你本地local specs repositories并沒(méi)有更新其下載版本導(dǎo)致灶芝。
比如 Unable to satisfy the following requirements: - SDWebImage (~> 3.8)
required by Podfile
處理方式有兩種:
1、pod update
更新本地庫(kù)
2唉韭、降低Podfile文件中的版本夜涕;
4. 使用CocoaPods之后,頭文件無(wú)法自動(dòng)補(bǔ)齊問(wèn)題
使用CocoaPods來(lái)管理三方庫(kù)属愤,還是比較方便的女器,但是突然發(fā)現(xiàn)一個(gè)美中不足的小問(wèn)題,在使用import引入文件時(shí)住诸,不能自動(dòng)補(bǔ)齊晓避,需要手工copy文件名,糾結(jié)了半天:
解決辦法:
Target -> Build Settings 只壳,User Header Search Paths條目中,添加${SRCROOT}
或者$(PODS_ROOT)
暑塑,并且選擇Recursive吼句,遞歸搜索,然后就可以自動(dòng)補(bǔ)齊了事格。
5. 在項(xiàng)目中移除CocoaPods三方庫(kù)配置文件
如果我們?cè)谂渲肅ocoaPods的三方庫(kù)文件后惕艳,不在需要了可以移除指定庫(kù)文件配置,具體步驟如下:
刪除工程文件夾下的Podfile驹愚、Podfile.lock和Pods文件夾远搪;
刪除xcworkspace文件;
打開(kāi)xcodeproj文件逢捺,刪除項(xiàng)目中的libpods.a和Pods.xcconfig引用谁鳍;
打開(kāi)Build Phases選項(xiàng),刪除Check Pods Manifest.lock和Copy Pods Resources;
-
重新pod install
如果不想使用pod了倘潜,可以使用 pod deintegrate绷柒,移除三方庫(kù),手動(dòng)添加涮因。
6. Pods written in Swift can only be integrated as frameworks; add use_frameworks!
to your Podfile or target to opt into using it.
這種提示废睦,主要是因?yàn)橐砑拥倪@個(gè)庫(kù)有專(zhuān)有swift庫(kù),或者demo中有swift代碼养泡。
解決辦法:在Podfile文件的target后面添加use_frameworks!
,注意嗜湃,這里有!。
比如[!] Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfile or target to opt into using it. The Swift Pods being used are: ReactiveCocoa, ReactiveSwift, and Result
7. The XXXX [Debug]
target overrides the HEADER_SEARCH_PATHS
build setting defined in `Pods/Target Support Files/Pods-XXXX/Pods-XXXX.debug.xcconfig'. This can lead to problems with the CocoaPods installation
或者
The XXXX [Debug]
target overrides the OTHER_LDFLAGS
build setting defined in `Pods/Target Support Files/Pods-XXXX/Pods-XXXX.debug.xcconfig'. This can lead to problems with the CocoaPods installation
參考:the-target-overrides
解決方法:
Go to your target Build Settings -> Other linker flags -> double click . Add $(inherited) to a new line.
All these 3 errors would be gone by adding $(inherited) to
Header Search Paths
Other Linker Flags
Preprocessor Macros
in Project -> Target -> Build Settings
重新pod
pod install
再或者
The XX [Debug]
target overrides the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES
build setting defined in `Pods/Target Support Files/Pods-XX/Pods-XX.debug.xcconfig'. This can lead to problems with the CocoaPods installation
解決方法:
在build setting 搜索ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES澜掩,選擇該條目购披,按delete鍵。
8. Xcode10版本工程cocoapod <=1.5.3問(wèn)題
RuntimeError - [!] Xcodeproj doesn't know about the following attributes {"inputFileListPaths"=>[], "outputFileListPaths"=>[]} for the 'PBXShellScriptBuildPhase' isa.
RuntimeError - [!] Xcodeproj doesn't know about the following attributes {"inputFileListPaths"=>[], "outputFileListPaths"=>[]} for the 'PBXShellScriptBuildPhase' isa.
參考:RuntimeError - [!] Xcodeproj doesn't know about the following
解決辦法:
This is a known bug introduced by Xcode 10 which fixed in CocoaPods 1.6.0. Right now (Sep 2018) it's in beta, so you can install it with
sudo gem install cocoapods --pre
或者
sudo gem install -n /usr/local/bin cocoapods --pre
Alternative solution for CocoaPods 1.5.3 could be found here.
9. Errno::EPERM - Operation not permitted @ chmod_internal
Errno::EPERM - Operation not permitted @ chmod_internal - /Users/admin/Desktop/SoamBaMeng/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1346:in `chmod'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1346:in `chmod'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1001:in `block in chmod'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1000:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1000:in `chmod'
這個(gè)問(wèn)題為文件訪問(wèn)權(quán)限問(wèn)題
解決辦法:
移除Pods文件夾输硝,重新pod install
10. error: RPC failed fatal: early EOF
......
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
解決辦法
admin:~ admin$ git config --global http.postBuffer 24288000
admin:~ admin$ git config --list
credential.helper=osxkeychain
http.postbuffer=24288000
11.Please contact the author or set the SWIFT_VERSION
attribute in at least one of the targets that integrate this pod.
例如:
- `ChartsRealm` does not specify a Swift version and none of the targets (`Ates`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.
- `RealmSwift` does not specify a Swift version and none of the targets (`Ates`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.
解決辦法今瀑,如果是純OC工程,請(qǐng)嘗試新建一個(gè)Swift類(lèi)点把,生成橋接文件橘荠,然后,選中對(duì)應(yīng)的target郎逃,--> build setting --> Swift Compiler Language --> Swift Language Version哥童,選擇一個(gè)Swift版本。
本文已在版權(quán)印備案褒翰,如需轉(zhuǎn)載請(qǐng)?jiān)诎鏅?quán)印獲取授權(quán)贮懈。
獲取版權(quán)