iOSiOS 开发 iOS

CocoaPods新版使用,遇到的那些坑!(Markdown版)

2016-10-10  本文已影响6861人  ZPengs

声明:首先网上找到的这个是可以用的,我只是整理一下方便统一查阅。让遇到问题的朋友,看着一篇文章就够了,不用再去东找西找解决问题了。

如果你遇到啦env: ruby_executable_hooks: No such file or directory这个问题粗暴点重新按着步骤安装一下好了。

一、第一部分新版安装

** 最新版 CocoaPods 的安装流程**

1.移除现有Ruby默认源
$gem sources --remove https://rubygems.org/
2.使用新的源
$gem sources -a https://ruby.taobao.org/
3.验证新源是否替换成功
$gem sources -l
4.安装CocoaPods
(1) $sudo gem install cocoapods 备注:苹果系统升级 OS X EL Capitan 后改为$sudo gem install -n /usr/local/bin cocoapods
(2) $pod setup
(3)$pod --version 查看CocoaPods版本
5.更新gem
$sudo gem update --system
6. 新建工程,并在终端用cd指令到文件夹内
$pod search 第三方
7.新建文件 vim “Podfile”,
$vim Podfile
写入以下内容并保存 小提示:(终端vim文件 按 i 可编辑 ,esc 退出编辑,:wq  可保存退出)
platform:ios, '6.0'
pod 'AFNetworking', '~> 2.3.1'    <-------第三方
8.导入第三方库
$pod install
9.退出终端

使用 pod install 还是 pod update 区别

二、安装使用过程中遇到的一些错误!总结:

终端 cocoapods 下载bug调试:

错误1:

Error fetching[http://ruby.taobao.org/:](http://ruby.taobao.org/:)
bad response Not Found 404 ([http://ruby.taobao.org/specs.4.8.gz](http://ruby.taobao.org/specs.4.8.gz))
解决方案:把安装流程中
 $gem sources -a[http://ruby.taobao.org/](http://ruby.taobao.org/)---改为---->$gem sources -a[https://ruby.taobao.org/](https://ruby.taobao.org/)

错误2:

ERROR:  While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决方案:苹果系统升级OS X EL Capitan后会出现的插件错误,将安装流程 4.安装CocoaPods 的 (1)sudo gem install cocoapods ——>改为sudo gem install -n /usr/local/bin cocoapods

错误3:

[!] Unable to satisfy the following requirements: - `AVOSCloud (~> 3.1.6.3)` required by `Podfile`
Specs satisfying the `AVOSCloud (~> 3.1.6.3)` dependency were found, but they required a higher minimum deployment target.
解决方案:安装流程:Podfile文件 中  platform:ios, ‘6.0’  后边的 6.0 是平台版本号 ,一定要加上
同样朋友们也可以看这位笔友写的:CocoaPods的安装使用和常见问题http://www.jianshu.com/p/6e5c0f78200a

错误4:

安装第三方库遇到的错误.png

这个问题解决可以点击这里
*** 如果那个连接上面写的不明确就照这个来:***
出错原因:podfile升级之后到最新版本,pod里的内容必须明确指出所用第三方库的target,否则会出现The dependency `` is not used in any concrete target这样的错误。:

以下从三个步骤陈述:

Podfile升级

1、查看pod版本:pod --version
2、pod 升级(此时是升级到1.0.0.beta.2版本):sudo gem install cocoapods --pre

错误内容:

如果你的Podfile的内容是:

如果你的Podfile的内容是.png
pod install 后出现错误 The dependency `` is not used in any concrete target
出现错误.png
修改方法:注意 target 要换成你自己的target
Podfile内容更改.png

错误5:

如果你也和我一样遇到啦这个问题:library not found for -lPods-AFNetworking

恭喜你了:问题现在解决了就是这个样:
是因为 cocoapods 升级后格式变了,
从某个版本开始, 在 builldsetting -> other linker flags 把-lPods-AFNetworking改成-l"AFNetworking", 其他的一样。 
你先把所有的库移除掉再重新 pod install 也可以

错误6:

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

解决方案
安装 RVM baby 版本管理器

$curl -L get.rvm.io | bash -s stable

等安装完成 出现下面这行提示以下

Incaseofproblems:https://rvm.io/helpandhttps://twitter.com/rvm_io

执行

$source ~/.bashrc $source ~/.bash_profile

测试是否安装正常

$rvm -v

提示以下

rvm 1.27.0 (latest) by Wayne E. Seguin, Michal Papis[https://rvm.io/]

用RVM升级Ruby查看当前ruby版本

$ruby -v $rvm list known

提示以下
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.8]
[ruby-]2.2[.4]
[ruby-]2.3[.0]
[ruby-]2.2-headruby-head
# for forks use: rvm install ruby-head---url https://github.com/github/ruby.git --branch 2.2
# JRuby
安装ruby 2.2.2 执行

$rvm install 2.2.2

如果打印:
![www(http:https://img.haomeiwen.com/i436736/cfad69fcfe1119f3.gif?imageMogr2/auto-orient/strip)
……  ruby-2.2.2-#validate archive
ruby-2.2.2-#extract
ruby-2.2.2-#validate binary
ruby-2.2.2-#setup
ruby-2.2.2- #gemset created /Users/abc/.rvm/gems/ruby-2.2.2@global
ruby-2.2.2- #importing gemset
/Users/abc/.rvm/gemsets/global.gems..............................
ruby-2.2.2- #generatingglobalwrappers........
ruby-2.2.2- #gemset created /Users/abc/.rvm/gems/ruby-2.2.2ruby-2.2.2- #importing gemsetfile /Users/abc/.rvm/gemsets/default.gems
evaluated to empty gem list    ruby-2.2.2- #generatingdefaultwrappers........
Updating certificatesin'/etc/openssl/cert.pem'.
mkdir:/etc/openssl: Permission denied
mkdir-p"/etc/openssl"failed, retrying with sudo
LiuWenqiang password requiredfor'mkdir -p /etc/openssl':
and sudo mkdir worked

![](http:https://img.haomeiwen.com/i436736/e9b71ac6486db8a5.gif?imageMogr2/auto-orient/strip)
则说明安装成功了
打印代码:
![](http:https://img.haomeiwen.com/i436736/6d3824c1c83ffcbd.gif?imageMogr2/auto-orient/strip)
Done with Command Line Tools (OS X10.11)forXcode
Done.==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress==>Installing the Command Line Tools (expect a GUI popup):==> /usr/bin/sudo /usr/bin/xcode-select --install
xcode-select: error: command line tools are already installed, use"Software Update"to install updates
Failed during:/usr/bin/sudo /usr/bin/xcode-select --install
Requirements installation failed with status:1.

![](http:https://img.haomeiwen.com/i436736/f2d5eb0051219eff.gif?imageMogr2/auto-orient/strip)
继续安装 CocoaPods
$sudo gem install cocoa pods
$sudo gem install -n /usr/local/bin cocoapods
$pod setup
更新 gem

$sudo gem update --system

6.新建一个项目,名字PodTest

错误7:

**[!]Pod::Executable clone'https://github.com/CocoaPods/Specs.git' master
xcrun: error: active developer path ("/Users/xiakejie/工具/Xcode 2.app/Contents/Developer") does not exist, use xcode-select to change**

解决上面这个问题,使用这个命令: sudo xcode-select-switch/Applications/Xcode.app/Contents/Developer

错误8:

**[!] Unable to satisfy the following requirements:**
**- `xxwnload (= 1.0.1)` required by `Podfile`**
**None of your spec sources contain a spec satisfying the dependency: `xxownload (= 1.0.1)`.**

解决上面这个问题,使用这个命令:pod setup或者pod update --verbose
耐心等一下需要的时间较长。

错误9:

Paste_Image.png
[!] Error installing Alamofire
[!]/usr/bin/gitclonehttps://github.com/Alamofire/Alamofire.git/var/folders/df/78n63m8s637ffyp78cclhtj00000gn/T/d20161010-1282-y78he1 --template= --single-branch --depth 1 --branch 4.0.0

解决方法:执行sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer(-switch 后面加上你的Xcode.app包内容里的Developer的文件夹路径即可)

错误10:

**[!] /usr/bin/curl -f -L -o /var/folders/df/78n63m8s637ffyp78cclhtj00000gn/T/d20161010-1307-1x4n64o/file.zip https://d3e51fp79zp4el.cloudfront.net/library/ios/v5.6/helpshift-sdk-ios-v5.6.1.zip --create-dirs --netrc-optional
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
 56 36.4M   56 20.6M    0     0  22343      0  0:28:30  0:16:07  0:12:23     0curl: (56) SSLRead() return error -9806
**
66D148B1-E0AA-4989-8729-DC3F6F5DF2AE.png

解决方法:
错误原因:下载这个库的时候超时了(超时的原因有很多但是这个的原因是):很简单需要翻墙。 具体怎么翻作为猿我就不多说了应该有很多。翻墙成功之后 pod install就搞定了。

错误11:

[!] /bin/bash -c 
set -e
sh build.sh cocoapods-setup

core is not a symlink. Deleting...
Downloading dependency: core 1.5.0
Downloading core failed:
curl: (56) SSLRead() return error -9806

解决方法: rm -rf Pods,删除工程目录下的pods文件夹,然后重新 pod install,安装Realm的时候会慢一些,等了很长时间...解决方 法 参考链接

curl https://static.realm.io/downloads/core/realm-core-0.96.0.tar.bz2 -O
mkdir $TMPDIR/core_bin
mv realm-core-0.96.0.tar.bz2 $TMPDIR/core_bin

错误12:

realm pod 报错'object_schema.hpp' file not found

1. rm -rf Pods
2. rm -rf ~/Library/Caches/CocoaPods

错误13:

[!] The `test [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 `test [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.

解决方法:
产生此警告的原因是项目 Target 中的一些设置,CocoaPods 也做了默认的设置,如果两个设置结果不一致,就会造成问题。
方法一:
我想要使用 CocoaPods 中的设置,分别在我的项目中定义PODS_ROOTOther Linker Flags的地方,把他们的值用$(inherited)替换掉,进入终端,执行:
pod install
方法二:
点击项目文件 project.xcodeproj,右键显示包内容,用文本编辑器打开project.pbxproj,删除OTHER_LDFLAGS的地方,保存,回到 Xcode,编译通过。
理论上就OK了。不过我还碰到这种情况类似,但解决路径不一样
相似错误:

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

[!] The `Swiot [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-Swiot/Pods-Swiot.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.
看我标红的路径.png

解决方法:就是分别在我的项目中
Build Settiongs->搜索HEADER_SEARCH_PATHS这个
地方,添加$(inherited),进入终端,执行:pod install
之后完美解决

错误14:

当执行 pod install 时出现这个警告

[!] The version of CocoaPods used to generate the lockfile (1.2.1) is higher than the version of the current executable (1.1.1). Incompatibility issues may arise.

解决方法:1、执行:pod repo update 命令更新资源库。
2、升级一下pod 执行命令:sudo gem install cocoapods 备注:苹果系统升级 OS X EL Capitan 后改为$sudo gem install -n /usr/local/bin cocoapods

                                              --------- By ZPengs
上一篇下一篇

猜你喜欢

热点阅读