系統(tǒng)環(huán)境:macOS Mojave 10.14.6
1. 安裝 RVM
- 開始安裝
1 | curl -L get.rvm.io | bash -s stable
- 進入目錄
1 | source ~/.bashrc
2 | source ~/.bash_profile
- 成功后查看版本
1 | rvm -v
2. Ruby升級
- 獲取Ruby版本
1 | ruby -v
- 對比Ruby版本
1 | rvm list known
- 更新Ruby
1 |rvm install 2.7.0-preview1
3. 更換Ruby源
- 查看當前源
1 | gem sources -l
- 移除默認源
1 | gem sources --remove https://ruby.taobao.org/
- 替換源
1 | gem sources -a https://gems.ruby-china.com/
(尾巴這條斜桿需要斟酌移除)
4. 安裝CocoaPods
- OS X 10.11之前系統(tǒng)的安裝cocoapods 指令
1 | $ sudo gem install cocoapods
- OS X 10.11以后系統(tǒng)的安裝cocoapods 指令
1 | $ sudo gem install -n /usr/local/bin cocoa pods
- 安裝
1 | pod setup
- 完成之后
1 | pod --version //查看版本
- 測試一下
1 | pod search AFNetworking
使用流程
1 | cd 目標路徑
2 | pod init
- 然后操作Podfile文件,一般使用vim
# Uncomment the next line to define a global platform for your project
platform :ios, '8.0'
target 'ProjectName' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod 'AFNetworking'
end
- 完成它
1 | pod install
- 如若比較慢凰盔,可使用{??}户敬,無須更新本地庫情況下(更新同理)
1 | pod install --no-repo-update
打開白色工程 projectName.xcworkspace
5. 更新CocoaPods
1 | sudo gem install -n /usr/local/bin cocoapods --pre
6. 更新CocoaPods 1.8.+版本本地庫
- 1.8+強制安裝了新的源trunk,采用cdn替換了原本的master
- 直接通過cdn方式更新本地庫
iMac:mac$ pod install
Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There are 28 dependencies from the Podfile and 32 total pods installed.
問題與解決
-
RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
- 可使用如下命令解決:
git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
///因Coding停止維護,可切別的源~
* https://code.aliyun.com/Magi/CocoaPods.git
* https://gitclub.cn/CocoaPods/Specs.git `推薦`
- 如果pod install中發(fā)現(xiàn):
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.
- 可嘗試直接更新最新版本
1 | sudo gem install cocoapods --pre
或者
pod repo update
or withpod install --repo-update
- 如果還是不行凡泣,可移除緩存重新安裝
// 移除本地master
sudo rm -fr ~/.cocoapods/repos/master
// 移除本地緩存
sudo rm -fr ~/Library/Caches/CocoaPods/
// 重新setup皮假,如果很慢可使用問題1的解決方法(git clone)
pod setup --verbose
- 更新時惹资,CocoaPods 1.8.0 的trunk問題
[!] CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/ Response: 400
- 可使用脫離trunk方式,打開podfile文件猴誊,頂部添加{??}侮措,指定舊方式下載
//source `源地址` podfile文件中指定source源為master:
source 'https://github.com/CocoaPods/Specs.git'
- 可移除trunk
1 | pod repo remove trunk
- podfile文件中添加source源后萝毛,pod install和pod update可以正常操作,但是pod search有些庫卻不正常笆包。
解決辦法:1. podfile文件中指定source源為master:source 'https://github.com/CocoaPods/Specs.git' 2.執(zhí)行pod repo remove trunk移除trunk源 執(zhí)行完后庵佣,pod search就都正常了! 通今。
- 更新系統(tǒng)與Xcode后肛根,出現(xiàn) Failed to extract git version from ·git --version· ??
macdeMacBook-Air:~ mac$ pod --version
Traceback (most recent call last):
7: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/ruby_executable_hooks:24:in `<main>'
6: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/ruby_executable_hooks:24:in `eval'
5: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/pod:23:in `<main>'
4: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/bin/pod:23:in `load'
3: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/bin/pod:55:in `<top (required)>'
2: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods/command.rb:49:in `run'
1: from /Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods/command.rb:130:in `verify_minimum_git_version!'
/Users/mac/.rvm/rubies/ruby-2.7.0-preview1/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods/command.rb:118:in `git_version': Failed to extract git version from `git --version` ("xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun\\n") (RuntimeError)
- 解決方法
1 | xcode-select --install