CocoaPods是iOS项目标依靠办理东西,闪开发者可以快速集当作第三方开源库和添加依靠库。跟着Ruby、Gem、Mac OSX、Xcode和CocoaPods的更新,CocoaPods的安装方式也跟着转变,当然也会发生各类如许的问题。
打开Mac自带“终端”
在Launchpad找到“其他”软件文件夹,找到终端打开。
替代Ruby的默认源,移除rubygems.org和淘宝的,改为ruby-china源
gem sources --remove https://rubygems.org/
gem sources --remove https://ruby.taobao.org
gem source -a https://gems.ruby-china.com
验证是否当作功替代Ruby的默认源
gem sources -l
最后只保留:
https://gems.ruby-china.com
更新Mac 的Gem,Gem是办理Ruby库和法式的尺度包
sudo gem update --system
或者(Mac OSX 10.11之后)
sudo gem update -n /usr/local/bin —system
然后输入办理员权限暗码(看不到输入成果的,输完暗码之后直接回车)
完当作安装CocoaPods
sudo gem install cocoapods
或者(Mac OSX 10.11之后)
sudo gem install -n /usr/local/bin cocoapods
查找本身需要添加的第三方库
pod search + 库名
如输入:pod search AFNetworking 后,期待返回所有合适搜刮前提的成果。可以直接操纵的是:pod 'AFNetworking', '~> 3.1.0'
找到项目文件路径
在终端输入cd+空格,然后拖动项目文件夹到终端,主动生当作路径。
建立并编纂Podfile文件(可以终端操作,也可以直接手动操作)
终端输入:vim podfile 或者 pod init(保举)
编纂文件,没有文件就主动在当前目次添加一个文件再编纂。输入内容:
platform :ios, '8.0'
target “target名称” do
pod 'AFNetworking', '~> 3.1.0'
end
按Esc退出编纂,然后按Shift +冒号,输入wq退出文件编纂。
为项目导入第三方库和相关依靠库
终端输入:pod install
然后耐烦期待下载第三方库,若是文件年夜,可能要花长时候。终端会打印进度的。
至此,添加已经完当作。可以看到项目目次里面多了4个文件,今后运行工程都利用.xcworkspace文件,而不再用.xcodeproj了。
编纂Podfile文件,断根里面所有库,然后终端输入:pod install。这时会清空第三方库和相关依靠库。
删除之前的4个文件,Podfile、Podfile.lock、Pods文件夹和.xcworkspace文件。
然后打开.xcodeproj,删除项目中的libpods.a和Pods.xcconfig引用。
TARGETS - Build Phases 删除有关pods的选项,至此完当作删除。
Error fetching http://ruby.taobao.org/:
bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
申明:
链接不到Ruby淘宝源,常见的404错误,可能因为https替代http了。所以gem sources -a http://ruby.taobao.org/ 需要替代当作:gem sources -a https://ruby.taobao.org/
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems
申明:
Mac OSX 10.11不克不及利用sudo gem update —system了,需要替代当作:sudo gem update-n /usr/local/bin —system
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
申明:
Mac OSX 10.11不克不及利用sudo gem install cocoapods了,需要替代当作:sudo gem install -n /usr/local/bin cocoapods
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master-1`. You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
申明:
因为安装了多个Xcode导致路径变了,需要变换路径:sudo xcode-select -switch /Applications/Xcode6.4/Xcode.app
The dependency `` is not used in any concrete target
申明:
Podfile进级之后到1.0.0版本,Pod里的内容必需明白指出所用第三方库的target,所以在podfile文件需要明白:
target “YOUR_TARGRT_NAME” do
...
end
Error installing cocoapods:activesupport requires Ruby version >= 2.2.2.
申明:
在安装cocoapods过程中提醒需要Ruby的版本在2.2.2以上。
查看当前Ruby版本,输入指令:ruby -v
解决方式:
经由过程rvm安装新版Ruby,输入指令:curl -L get.rvm.io | bash -s stable
重装rvm,输入指令:rvm reload
然后安装Ruby,输入指令:rvm install ruby
若是呈现:Requirements installation failed with status: 1.则需要输入:
第一行:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
第二行:rvm autolibs read-only # read more here:https://rvm.io/rvm/autolibs
第三行,再次安装:rvm install ruby
然后终端就疯狂的起头下载了。
[!] Unable to find a pod with name, author, summary, or description matching `xxx`
申明:
搜刮库:pod search xxx报错;
是search_index.json这个文件的原因,可以将其删除,然后从头生当作便可解决此问题。
解决方式:
输入指令:rm ~/Library/Caches/CocoaPods/search_index.json
完当作即可从头搜刮。
0 篇文章
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!