Updated on 四月 4, 2019
CocoaPods踩过的坑
CocoaPods是专门为iOS工程提供第三方依赖库的管理工具,通过CocoaPods可以更方便地管理每个第三方库的版本
安装
Ruby使用macOS自带的Ruby就可以,不必安装。
sudo gem install cocoapods #安装cocoapods
我应该是很久以前安装过了,电脑上已经有cocoapods了。
使用
比如项目要依赖某个库,到那个库的github readme页面发现,上面写着使用pod ‘Pitchy’来install。
首先要在项目目录下生成Podlist文件,把pod ‘Pitchy’ 复制到文件中。
生成Podlist
terminal cd到项目路径,然后执行pod init,这样就在项目根目录下生成了Podlist文件。
编辑Podlist文件,将pod ‘Pitchy’ 复制到文件中。
安装依赖包
执行pod install安装依赖包
但是报错:
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master`. You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
上网查说是需要更新cocoapods
pod update --no-repo-update
结果报错 Abort trap: 6。
sudo gem uninstall cocoapods sudo gem install cocoapods --pre #结果又报错: ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why: Unable to download data from https://gems.ruby-china.org/ - bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz) #添加源,并且把其他的源删除掉: gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ https://gems.ruby-china.com/ added to sources source https://rubygems.org/ not present in cache #查看当前源 gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.org/ https://gems.ruby-china.com/ #继续删 gem sources --remove https://gems.ruby-china.org/ https://gems.ruby-china.org/ removed from sources gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.com/ #再次执行 sudo gem install cocoapods --pre #安装成功 #这时再执行install (--verbose可能是打印log?) pod install --verbose --no-repo-update #成功
然后打开xcworkspace文件,就可以了。