1. 程式人生 > >cocoapods:常見錯誤總結

cocoapods:常見錯誤總結

錯誤1

無論是執行pod install還是pod update都卡在了Analyzing dependencies 或者 Updating local specs repositories不動

解決方案:

原因在於當執行以上兩個命令的時候會升級CocoaPods的spec倉庫,加一個引數可以省略這一步,然後速度就會提升不少。加引數的命令如下:

pod install --verbose --no-repo-update
pod update --verbose --no-repo-update

錯誤2

pod 命令執行報下面錯誤:

Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.

解決方案:

不要使用文字編輯去編輯Podfile,使用Xcode編輯,或者使用終端敲命令去編輯。或者輸入格式錯誤,沒輸入執行版本:

platform:iOS, '7.0'

錯誤3

使用cocoapods匯入第三方類庫後頭檔案沒有程式碼提示

解決方案:

選擇Target -> Build Settings 選單,找到\”User Header Search Paths\”設定項,新增一個值"${SRCROOT}",並且選擇\”Recursive\”

錯誤4

The dependency ‘xxx’ is not used in any concrete target.

解決方案:

解決: 這個錯誤是說明你沒有使用下面的格式, 將 Podfile編輯成下面的格式

 platform :ios,'7.0'
target '你的app的target名字' do
    pod 'AFNetworking', '2.0'
    pod 'SDWebImage', '3.7'
    ...
end     

錯誤5

安裝時報錯如下:

Setting up CocoaPods master repo
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master –depth=1
Cloning into ‘master’…
error: RPC failed; result=18, HTTP code = 200
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

解決方案:

$ git config --global http.postBuffer 24288000
$ git config --list

若輸出 http.postbuffer=24288000, 就 OK了

錯誤6

在 pod install 時, 可以生成要匯入的第三庫, 但是其標頭檔案找不到, 檔案有缺失, target 設定沒有完成.

[!] The `Paopao [Debug]` target overrides the `PODS_ROOT` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

[!] The `Paopao [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

[!] The `Paopao [Release]` target overrides the `PODS_ROOT` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

[!] The `Paopao [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

解決方案:

方案一:
產生此警告的原因是專案 Target 中的一些設定,CocoaPods 也做了預設的設定,如果兩個設定結果不一致,就會造成問題。
我想要使用 CocoaPods 中的設定,分別在我的專案中定義PODS_ROOTOther Linker Flags的地方,把他們的值用$(inherited)替換掉,進入終端,執行 pod update , 然後錯誤沒了.

方案二:
這個方案比較簡單粗暴。點選專案檔案 project.xcodeproj,右鍵顯示包內容,用文字編輯器開啟project.pbxproj,刪除OTHER_LDFLAGS的地方,儲存,執行pod update,錯誤沒了

錯誤7

引用要匯入的三方庫缺少 .o 檔案的錯誤:

“_OBJC_CLASS_S_SomeClass”, referenced from:
Objc-class-ref in OtherClass.o

具體錯誤如下圖:
這裡寫圖片描述

解決方案:

在Build Setting 中的Other Linker Flags選項中加入$(OTHER_LDFLAGS)

錯誤8

還有一個複雜些的錯誤, 在為新專案配置 cocoapods 時遇到的:

LoadError - dlopen(/Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/psych.bundle, 9): Library not loaded: /usr/local/lib/libyaml-0.2.dylib
Referenced from: /Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/psych.bundle
Reason: image not found - /Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/psych.bundle

解決方案:

見錯誤9

錯誤9

還有一個是在解除安裝 cocoapods時遇到的:

Error loading RubyGems plugin “/Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/gems/2.0.0/gems/gem-wrappers-1.2.7/lib/rubygems_plugin.rb”: dlopen(/Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/openssl.bundle
Reason: image not found - /Users/MyMac/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/x86_64-darwin14.1.0/openssl.bundle (LoadError)

解決方案:

這兩個問題, 解決方案都一樣, 一般都是rvm的問題, 所以你需要先解除安裝rvm和ruby, 然後再重新安裝rvm和ruby。 具體命令請參考我的另一篇文章cocoapods:安裝/更新Ruby環境教程

錯誤10

Mac OS X 更新到10.11後cocoapods安裝出現的問題

$ sudo gem install cocoapods
ERROR: Could not find a valid gem ‘cocoapods’ (>= 0), here is why:
Unable to download data from http://ruby.taobao.org/ - bad response Not Found 404 (http://ruby.taobao.org/latest_specs.4.8.gz)

解決方案:

方案一:

將淘寶映象的http改為https

$ gem sources --remove http://ruby.taobao.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l

再安裝就可以了

$ sudo gem install cocoapods

方案二:

$ gem source -a http://rubygems.org/

再安裝就可以了

$ sudo gem install cocoapods

關於 ruby環境需要升級更新的問題

錯誤11

ERROR: Error installing cocoapods: activesupport requires Ruby version >= 2.2.2.

解決方案:
原因是安裝cocoapods過程中提示需要Ruby的版本在2.2.2以上,而目前使用的Ruby版本是Mac系統自帶的1.8.7。所以需要對Ruby進行升級。以下是安裝Ruby的三種方法:
1.下載ruby原始碼,編譯,安裝
2.使用發行版自帶的安裝包,安裝
3.使用 rvm安裝
在這裡還是推薦大家通過rvm對Ruby進行升級,具體的步驟這裡就不贅述了, 需要的請檢視我的部落格之 cocoapods:安裝/更新Ruby環境教程, 裡面有通過rvm安裝ruby的具體操作.

錯誤12

ERROR: While executing gem … (Gem::DependencyError)
Unable to resolve dependencies: cocoapods requires cocoapods-core (= 1.2.0), cocoapods-downloader (< 2.0, >= 1.1.3), cocoapods-trunk (< 2.0, >= 1.1.2), molinillo (~> 0.5.5), xcodeproj (< 2.0, >= 1.4.1); activesupport requires thread_safe (>= 0.3.4, ~> 0.3); tzinfo requires thread_safe (~> 0.1)

解決方案:
需要更新ruby版本

錯誤13

ERROR: While executing gem … (Errno::EPERM) Operation not permitted - /usr/bin/xcodeproj

解決方案:

sudo gem install -n /usr/local/bin cocoapods

治標不治本, 根本上還是需要重新安裝或者更新ruby

關於 pod setup/ pod install 錯誤總結

錯誤14

$ pod install
Analyzing dependencies
[!] Unable to satisfy the following requirements:
-AFNetworking (~> 3.0) required by Podfile
None of your spec sources contain a spec satisfying the dependency: AFNetworking (~> 3.0).
You have either:
* out-of-date source repos which you can update with pod repo update.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.

解決方案:

$ pod repo remove master
$ pod repo add master https://gitcafe.com/akuandev/Specs.git
$ pod repo update

錯誤15

$ pod setup
Setting up CocoaPods master repo
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master
Cloning into ‘master’…
error: RPC failed; curl 56 SSLRead() return error -36
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

解決方案:

$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

並一定是這行程式碼,要根據自己的情況,來修改這個命令列, 也許你是多個xcode, 那麼你的命令列就要修改一下:

$ sudo xcode-select -switch /Applications/Xcode 7.3.1.app/Contents/Developer

錯誤16

$ pod setup
Setting up CocoaPods master repo
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master
Cloning into ‘master’…
error: RPC failed; curl 56 SSLRead() return error -9806
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

解決方案:
見錯誤16

錯誤17

$ pod setup
Setting up CocoaPods master repo
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master
Cloning into ‘master’…
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

解決方案:
這些怎麼解決呢? 其實mac OS 10.11之後, cocoapods的一些命令需要進行變化,今天來總結一下. 如果你遇到了pod setup或者pod update 的問題了, 而且很難解決, 我建議不如解除安裝重灌. 10.11 之後, 安裝cocoapods有一些不同的命令, 下面總結一下:

1.檢查ruby環境,若需要請按如下更新

$ sudo gem update --system

2.解除安裝cocoapods

$ sudo gem uninstall cocoapods

3.重灌cocoapods (安裝命令有變化)
10.11之前

$ sudo gem install cocoapods

10.11之後

$ sudo gem install -n /usr/local/bin cocoa pods

4.

$ sudo chmod +rx /usr/local/bin
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

//將 CocoaPods Specs repository複製到你電腦上~/.cocoapods目錄下

pod setup