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 “ 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](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_ROOT 和 Other Linker Flags的地方,把他們的值用$(inherited)替換掉,進入終端,執行 pod update , 然后錯誤沒了.

還有一種簡單粗暴的方法:
點擊項目文件 project.xcodeproj,右鍵顯示包內容,用文本編輯器打開project.pbxproj,刪除OTHER_LDFLAGS的地方,保存,執行pod update,錯誤沒了
7.引用要導入的三方庫缺少 .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.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/](http://ruby.taobao.org/) - bad response Not Found 404 ([http://ruby.taobao.org/latest_specs.4.8.gz](http://ruby.taobao.org/latest_specs.4.8.gz))

更新ruby后也沒有解決, 最后發現是由于淘寶鏡像失效了,http://ruby.taobao.org/失效了 解決方案有兩個: 1>將淘寶鏡像的http改為https

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

再安裝就可以了

sudo gem install cocoapods

2>后來在stackoverflow上看到一個回答 是關于gem install fails with openssl failure,將淘寶鏡像替換為http://rubygems.org/.

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

再安裝就可以了

$ sudo gem install cocoapods

10.ruby環境需要升級更新 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環境教程, 里面有通過ram安裝ruby的具體操作.
11.pod setup/ pod install 錯誤總結
問題1:

$ 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

問題2:

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

問題3:

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

問題4:

$ pod setup Setting up CocoaPods master repo [!] /usr/bin/git clone [https://github.com/CocoaPods/Specs.git](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
$ sudo chmod +rx /usr/local/bin
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

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

pod setup

原文引自 http://blog.csdn.net/wangyanchang21/article/details/51437934

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容