最近使用cocoaPods,但是使用过程中遇到很多坑,在此记载一下:
刚开始遇到Unable to find a specification for 'xxx',然后又是各种错误,
弄了半天也没弄好,操作的方式见上一篇文章。
然后又听说淘宝镜像不能用了,cocoaPods版本也升级到了1.x.x了,我当前的是0.39.0,索性卸载一下重新安装。
1.终端运行:sudo gem uninstall cocoapods,然后选“Y”。
2.然后运行:pod —version,看还剩下什么。
3.显示隐藏文件,地址http://jingyan.baidu.com/article/36d6ed1f524bf21bcf488331.html。最好重启一下Finder(option+command+esc).
4.删除掉.cocoaPods文件。
4.1.终端输入命令gem list --local | grep cocoapods,删除这个列表的所有文件:sudo gem uninstall cocoapods-core等
5.重装cocoaPods(我安装的是1.0.0):sudo gem install -n /usr/local/bin cocoapods -v 1.0.0(注1),安装成功以后可以看一下版本:pod —version。更新:如果是第一次安装cocoapods提示镜像问题,先执行第6步
圈起来的ERROR可以先不用管,具体原因及其解决方式见(注1)
6.查看一下ruby源:gem source -l
如果以前弄过淘宝的的镜像,那么运行:
(1)$ gem sources -r https://rubygems.org/ (移除旧版本的镜像)
(2)$ gem sources -a https://gems.ruby-china.org/ (增加可用的镜像)。更新:使用.com替换原来的.org。$ gem sources -a https://gems.ruby-china.com/
没有弄过的直接运行(2)
7.下载:pod setup
注1:
在运行第五步的时候,会出现一个ERROR,错误信息:
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Certification Authority to your local trusted store
ERROR: SSL verification error at depth 2: self signed certificate in certificate chain (19)
ERROR: Root certificate is not trusted (/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA)
解决方法:
$ sudo curl -O http://curl.haxx.se/ca/cacert.pem
$ sudo mv cacert.pem cert.pem
此时就下载完成了cocoapods了。
-------------------------------华丽的分割线--------------------------------------
那好,我们来使用一下
当pod install的时候会报一下错误(我先随便导入了'AFNetworking'):
The dependency `AFNetworking (~> 3.0)` is not used in any concrete target.
在Podfile中添加
target‘项目名'do (如 target 'Demo' do )
[!] Invalid `Podfile` file: syntax error, unexpected end-of-input, expecting keyword_end.
在Podfile的末尾添加 end
因为我们项目有两个target,引入的库都一样,我就试了一下link_with语法,结果也报错:
[!] Invalid `Podfile` file: [!] The specification of `link_with` in the Podfile is now unsupported, please use target blocks instead..
方法1:
target 'targetName1' do ... end
target 'targetName2' do ... end
方法2:
# target数组 如果有新的target直接加入该数组
targetsArray = ['targetName1', 'targetName2', 'targetName3', 'targetName4', 'targetName5']
# 循环
targetsArray.each do |t|
target t do
pod 'MJRefresh', '~> 1.4.6'
pod 'Masonry', '~> 0.6.1'
end
end
一般情况下的podfile文件
platform :ios, ’10.0’
use_frameworks!
target ‘CJLive’ do
pod ‘Alamofire’, ‘4.4’
pod ‘Kingfisher’, ‘~> 3.1.1’
end
---------------------------------------------------------分割线--------------------------------------------------------------
更新时发生以下错误:
[!] Unable to satisfy the following requirements:
- `Alamofire (= 4.4)` required by `Podfile`
None of your spec sources contain a spec satisfying the dependency: `Alamofire (= 4.4)`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --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.
是因为cocoapods版本太低,更新一下cocoapods
运行:
sudo gem install cocoapods
如果出现以下错误:
Operation not permitted - /usr/bin/xcodeproj
则可以用以下这段命令来代替:
sudo gem install -n /usr/local/bin cocoapods --pre
运行完别忘记安装(我又一次忘记了,搞了好久才发现的-.-):
pod setup
然后再次
pod install --verbose --no-repo-update
就可以了