Cocoapods的安装步骤
- 由于之前在安装Cocoapods遇到很多坑,所以在这里总结分享一下安装步骤。
更换源
- Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/)源来查找、安装、升级和卸载软件名
- gem sources –remove https://rubygems.org/
- gem sources -a http://ruby.taobao.org/
- gem sources -l
升级更新gem
- sudo gem update –system
安装
- sudo gem install cocoapods
更换repo镜像为国内服务器(“翻墙”->安装cocoapods比较快)
- pod repo remove master
- pod repo add master https://gitcafe.com/akuandev.Specs.git
- pod repo add master http://git.oschina.net/akuandev/Specs.git(有时候不可行)
初始化第三方库信息
- pod setup
以后更新第三方库信息
- pod repo update
搜索第三方库
- pod search xxx
新建Podfile
- vim Podfile
- 输入i:进入编辑状态
- 输入dd:删除当前行
- 按ESC:退出编辑模式
- 输入Ctrl + R:撤销操作
- 输入:wq:保存并退出
- Podfile文件的格式
platform :ios, 'sdk版本(例:8.0)'
pod '框架名字'
pod '框架名字', '~> 版本号'
解析Podfile,安装第三方框架
- pod install
解析Podfile,升级第三方框架
- pod update
以后使用Cocoapods过程中出现了莫名其妙的问题
- sudo gem update –system // cocoapods版本太旧,gem升级
- sudo gem install cocoapods // 重新安装cocoapods
- pod setup // 初始化第三方库信息
常见错误:
- 错误1:
Error fetching http://ruby.taobao.org/:
bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
解决方案:把安装流程中 gemsources−ahttp://ruby.taobao.org/−−−改为−−−−> gem sources -a https://ruby.taobao.org/
- 错误2:
ERROR: While executing gem … (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决方案:苹果系统升级OS X EL Capitan后会出现的插件错误,将安装流程安装CocoaPods 的 (1)sudo gem install cocoapods ——>改为sudo gem install -n /usr/local/bin cocoapods
- 错误3:
ERROR:The dependency` is not used in any concrete target
AFNetworking ` is not used in any concrete target
The dependency
解决方案:
1.安装cocoapods的预览版本
sudo gem install cocoapods –pre2.修改Podfile格式
platform :ios, ‘8.0’
target ‘MyApp’ do
pod ‘AFNetworking’, ‘~> 2.6’
pod ‘ORStackView’, ‘~> 3.0’
end
*里面的 MyApp 记得替换为自己攻城里面的target。3.更新pod
执行pod install / pod update 命令