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环境教程

我曾经写过解决此问题的详细步骤, 具体请参考 cocoapods:为新项目添加第三方类库时出错


错误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)

更新ruby后也没有解决, 最后发现是由于淘宝镜像失效了, http://ruby.taobao.org/失效了

解决方案:

方案一:

将淘宝镜像的http改为https

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

再安装就可以了

$ sudo gem install cocoapods

方案二:

后来在stackoverflow上看到一个回答 是关于gem install fails with openssl failure, 将淘宝镜像替换为http://rubygems.org/.

$ 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
$ sudo chmod +rx /usr/local/bin
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

//将 CocoaPods Specs repository复制到你电脑上~/.cocoapods目录下

pod setup

如果还不行,可以先删除.cocoapods目录:

sudo rm -rf ~/.cocoapods/

然后,重新pod setup。如果还解决不了,可以尝试:

$ sudo gem install -n /usr/local/bin cocoapods
$ Git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master

相关文章:
cocoapods:安装/更新Ruby环境教程
cocoapods:为新项目添加第三方类库时出错
Error loading RubyGems plugin ,openssl.bundle (LoadError)
gem install fails with openssl failure

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页