CocoaPods的安装和常见问题

2017-07-06  本文已影响65人  RadioWaves

一、什么是CocoaPods

二、CocoaPods的原理

三、CocoaPods的安装

$ sudo gem install cocoapods
ERROR: Could not find a valid gem 'cocoapods' (>= 0), 
here is why:Unable to download data from [https://rubygems.org/]
(https://rubygems.org/) - Errno::ETIMEDOUT: Operation timed out - connect(2) 
([https://rubygems.org/latest_specs.4.8.gz]
(https://rubygems.org/latest_specs.4.8.gz))ERROR: Possible alternatives: cocoapods
// 先删除当前所有的ruby源,然后替换成
$ gem sources -l (查看当前ruby的源)
$ gem sources --remove (https://rubygems.org/)
$ gem sources --remove (https://ruby.taobao.org/ )
$ gem sources -a (https://gems.ruby-china.org/)
$ gem sources -l
sudo gem update --system

升级成功后会提示:

RubyGems system software updated

然后重新执行安装下载命令

$ sudo gem install cocoapods

如果在安装过程中出现:下图问题



那就换个安装方法

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

这时候应该没什么问题了,接下来进行安装,执行:

$ pod setup

Terminal会停留在 Setting up CocoaPods master repo 这个状态一段时间,是因为要进行下载安装,而且目录比较大,需要耐心等待一下.如果想加快速度,可使用cocoapods的镜像索引.(文章末尾附使用镜像索引的方法)安装成功后,你会看到:


安装失败的解决方案

sudo gem update --system
sudo gem uninstall cocoapods
sudo gem install cocoapods

升级到10.11, CocoaPods报错: command not found 解决方案

sudo gem update --system
sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoa pods

注意在Xcode 7以后,要将cocoapods的GEM_PATH更换为下图


四、常见问题

[!] Invalid Podfile file: undefined local variable or method `en_US' for #
<Pod::Podfile:0x00000102a5d8b0>. Updating CocoaPods might fix the issue.

原因:单引号格式,可能是手动输入导致解决办法:系统偏好设置-键盘-文本-将“使用智能引号和破折号”一项取消勾选-再将podfile里面的单(双)引号修改一下

ArgumentError - invalid byte sequence in US-ASCII

原因:字符集错误解决办法:使用locale命令查看当前的字符集,如果都是zh,需要执行以下命令:

export LC_ALL=en_US.UTF-8export LANG=en_US.UTF-8

然后再使用locale命令查看,已经改过来了

[!] The YMTea [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 installationUse the $(inherited) flag, or Remove the 
build settings from the target.
[!] The YMTea [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.

原因:我是在已有项目中集成Cocoapods的时候遇到这个问题,原因是项目 Target 中做了一些设置,CocoaPods 也做了默认的设置,如果两个设置结果不一致,就会造成问题。解决方法:我想要使用 CocoaPods 中的设置,分别在我的项目中定义PODS_ROOTOther Linker Flags的地方(build settings,把他们的值用$(inherited)替换掉,进入终端,执行 pod update警告没了,回到 Xcode,build通过。
网上还流行另外一种简单粗暴的方法:点击项目文件 project.xcodeproj,右键显示包内容,用文本编辑器打开project.pbxproj,删除OTHER_LDFLAGS的地方,保存(这种我没试过)

 [!] Oh no, an error occurred.
It appears to have originated from your Podfile at line 2.
Search for existing GitHub issues similar to yours:
[https://github.com/CocoaPods/CocoaPods/search?
q=%2FUsers%2Fxiao6%2FMusic%2FGI06%E5%AE%9E%E8%AE%AD%E8%8A%B8%E
8%8C%97%E8%8C%B6%E5%8F%B6%2FYMTea%2FPodfile%3A2%3A+syntax+error%2
C+unexpected+%27%3A%27%2C+expecting+end-of-
input%0Aplatform+%3A+ios%2C+%277.0%27%0A++++++++++%5E&type=Issues]
(https://github.com/CocoaPods/CocoaPods/search?
q=%2FUsers%2Fxiao6%2FMusic%2FGI06%E5%AE%9E%E8%AE%AD%E8%8A%B8%E
8%8C%97%E8%8C%B6%E5%8F%B6%2FYMTea%2FPodfile%3A2%3A+syntax+error%2
C+unexpected+%27%3A%27%2C+expecting+end-of-
input%0Aplatform+%3A+ios%2C+%277.0%27%0A++++++++++%5E&type=Issues)
If none exists, create a ticket, with the template displayed above, on:
[https://github.com/CocoaPods/CocoaPods/issues/new]
(https://github.com/CocoaPods/CocoaPods/issues/new)
Be sure to first read the contributing guide for details on how to properly submit a ticket:
[https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md]
(https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md)
Don't forget to anonymize any private data!

原因:因为Podfile文件里面 platform 那一行 冒号和ios之间多了一个空格。。。。其实这个错误在报错的时候ruby已经给出了:


附:如何使用CocoaPods的镜像索引:

$ pod repo remove master
$ pod repo add master https://gitcafe.com/akuandev/Specs.git
$ pod repo update
这是使用gitcafe上的镜像,将以上代码中的 
https://gitcafe.com/akuandev/Specs.git 
替换成 
http://git.oschina.net/akuandev/Specs.git 
即可使用oschina上的镜像。

以上内容主要来源于http://www.jianshu.com/p/4291014e01d1

上一篇下一篇

猜你喜欢

热点阅读