統一專案Cocoapods版本和Gem環境
統一專案Cocoapods版本和Gem環境
通過Gem統一專案Cocoapods版本
-
檢測是否有
rbenv
,直接在命令列中輸入rbenv
,看是否會出現版本提示資訊。如果沒有出現,需要通過brew install rbenv
命令來安裝.如果安裝過程中出現如下報錯: ==> Pouring ruby-build-20220412.all.bottle.tar.gz Error: No such file or directory @ rb_sysopen - /Users/xxx/Library/Caches/Homebrew/downloads/4ff0b9e0c99846bf0bf4b5be5f73dc12cd27499bdeff6d8b6dede0f2b860f969--ruby-build-20220412.all.bottle.tar.gz\ 先安裝
ruby-build
,執行brew install ruby-build
\ 然後再次執行brew install rbenv
即可 -
使用
rbenv
管理Ruby
版本。3.0.0
是最新穩定版本,或者使用rvm install ruby --head
安裝rvm能夠支援的最新ruby
版本rbenv install 3.0.0
rbenv shell 3.0.0
1.檢視當前rvm版本可以管理的ruby版本列表
rvm list known
,如果rvm版本過低,高版本的ruby是安裝不了的2.
rvm list
檢視本地安裝的ruby版本使ruby環境生效
-
安裝後可以查詢系統級Gem依賴
gem list
使用Bundler管理工程中的Gem環境
-
在iOS工程中初始化Bundler環境,在工程主目錄中執行
bundle init
命令,這時主目錄中會生成一個Gemfile檔案.1.如果遇到如下錯誤:
/Users/xxx/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:281:in
find_spec_for_exe': Could not find 'bundler' (1.15.4) required by your /Users/xxx/app/demo/Gemfile.lock. (Gem::GemNotFoundException) To update to the latest version installed on your system, run
bundle update --bundler. To install the missing version, run
gem install bundler:1.15.4from /Users/xxx/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:300:in
activate_bin_path' from /Users/xxx/.rbenv/versions/3.0.0/bin/bundle:23:in<main>
可以根據報錯提示先執行
gem install bundler:1.15.4
,然後執行bundle init
2.如果已經存在
Gemfile
檔案,仍然執行bundle init
,會有如下報錯:Gemfile already exists at /Users/xxx/app/demo/Gemfile
-
編輯Gemfile,執行Pod的版本
```
frozen_string_literal: true
A sample Gemfile
source "https://gems.ruby-china.org"
source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } gem "cocoapods", "1.11.3" gem "fastlane" gem 'xcodeproj' gem 'badge' gem 'dotenv'
plugins_path = File.join(File.dirname(FILE), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path) ```
-
在當前主目錄中執行
bundle install
,執行完成之後,指定版本的Cocoapods就安裝成功了。可以通過pod --version
命令檢視版本號1.執行bundle install時,如果有如下報錯:
Could not reach host gems.ruby-china.org. Check your network connection and try again
檢查source源是不是"https://gems.ruby-china.org",改為"https://rubygems.org"
2.如果有如下衝突報錯:
Bundler could not find compatible versions for gem "xcodeproj": In snapshot (Gemfile.lock): xcodeproj (= 1.8.1)
In Gemfile: xcodeproj
cocoapods (= 1.11.3) was resolved to 1.11.3, which depends on xcodeproj (>= 1.21.0, < 2.0)
fastlane was resolved to 2.98.0, which depends on xcodeproj (>= 1.5.7, < 2.0.0)
Running
bundle update
will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict.執行
bundle update
,更新Gemfile.lock即可 -
在專案主目錄下執行
bundle exec gem list
可以檢視到當前Cocoapods的版本 -
執行
bundle exec pod install/update
就可以使用指定版本的Cocoapods進行install或update
- OC底層原理01-物件原理之alloc和init原始碼分析
- 統一專案Cocoapods版本和Gem環境
- VIPER架構初探
- 關於performSelector: withObject: afterDelay:的坑
- iOS底層原理:Block底層原理
- OC底層原理11 :類的載入(上)
- OC底層原理05-cache_t探索
- OC底層原理14:Method-Swizzling 方法交換
- OC底層原理07:訊息流程之慢速查詢
- OC底層原理16 :KVO 底層原理
- OC底層原理15:KVC 底層原理
- OC底層原理12:類的載入(下)
- iOS:啟動優化(二) Clang插樁及Order檔案
- OC底層原理08:訊息流程之動態方法決議 & 訊息轉發
- OC底層原理06:訊息流程之快速查詢
- OC底層原理10:dyld與objc的關聯
- iOS:介面優化方案
- iOS:啟動優化(一)基本概念
- iOS:元件化的三種通訊方案
- iOS:LLVM編譯流程 & Clang外掛開發