前言
話說公司給配了臺(tái)新Mac mini,M1處理器的,電腦到貨后是11.0.1 BigSur 系統(tǒng),電腦運(yùn)行速度確實(shí)是剛剛的,但是接下來在安裝cocoapoads上真是讓我有苦說不出啊,皇天不負(fù)苦心人,終于斷斷續(xù)續(xù)弄了三天后,搞定了,現(xiàn)在把過程大致記錄一下,希望能幫到其他同志,有些細(xì)節(jié)沒有記錄,只能靠感覺了。
首先
我們要明確,在m1處理器,11.0.1系統(tǒng)下安裝cocoapods和之前的安裝可以說是天壤之別,這也是本次安裝坑點(diǎn)之一,坑點(diǎn)2就是我們的英文都太差了,安裝過程中報(bào)的英文錯(cuò)誤看不懂。
這里請(qǐng)大家先花幾分鐘把文章看完了再來操作,這樣整個(gè)流程會(huì)清晰一點(diǎn)。
檢查電腦是否安裝homebrew
終端輸入:brew -v
brew -v
提示
Homebrew 3.0.9
Homebrew/homebrew-core (git revision 7fa7e5ada3e; last commit 2021-03-29)
Homebrew/homebrew-cask (git revision cdd3a8a406; last commit 2021-03-30)
我是更新了一下homebrew
檢查是否安裝rvm
終端輸入: rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
如果沒有安裝rvm,終端輸入以下命令:
curl -L get.rvm.io | bash -s stable
//執(zhí)行以上命令后,出現(xiàn)curl: (7) Failed to connect to raw.githubusercontent.com port 443:
//Connection refused
//則修改host文件,重新執(zhí)行curl -L get.rvm.io | bash -s stable命令,反之直接執(zhí)行指定源的命令。
修改host 文件,終端輸入以下命令行:sudo vi /etc/hosts,在host文件中加入以下的IP地址配置,如下所示:
sudo vi /etc/hosts
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
1)輸入本機(jī)密碼后,打開hosts文件,鍵盤輸入 i (插入),修改hosts文件后,按 esc 鍵退出,再按shift+:鍵,再輸入w和q,保存退出
(2)不保存退出,則按q和!鍵
指定源:
source ~/.rvm/scripts/rvm
rvm -v
// 安裝成功
// rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
安裝rvm可以參考這編文章中的安裝rvm介紹,注意只要關(guān)注他的安裝rvm介紹即可
重點(diǎn)來了 重點(diǎn)來了 ruby的版本切記不要使用3.0.0的版本
我用的是2.6.3的版本
我在指定ruby的時(shí)候 用的是這個(gè)命令:
rvm system --default
只要終端輸入ruby --version:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
只要出現(xiàn)這個(gè)即可,有些同志用rvm use 2.6.3 --default
會(huì)提示沒有安裝那是正常現(xiàn)象,我都沒有去管他,也不必去管他,只要你輸入ruby --version 出現(xiàn) 對(duì)應(yīng)的版本號(hào)即可。
接下來安裝cocoapods
sudo gem install cocoapods,,就算安裝過cocoapods一樣可以執(zhí)行一下,好安裝好之后,因?yàn)槲覀兪荕1處理器,所以我們需要額外安裝一個(gè)ffi插件,這里需要注意,我們的終端可以把"使用Rosetta打開"開關(guān)開啟,這樣我們就可以在終端直接輸入sudo gem install ffi
,然后我這邊提示了Building native extensions. This could take a while... Successfully installed ffi-1.15.0 Parsing documentation for ffi-1.15.0 Done installing documentation for ffi after 3 seconds 1 gem installed
如何打開那個(gè) rosetta開關(guān)呢,如下操作:
右鍵顯示簡(jiǎn)介
如果不勾選 rosetta開關(guān),可以在終端輸入 sudo arch -x86_64 gem install ffi
這里可以參考這編文章
關(guān)于m1處理器問題的可以看這篇文章
我這邊為了省事,就勾選了rosetta.
接下來注意
我們?cè)趐od setup 后,系統(tǒng)直接就setup completed,這個(gè)是正常現(xiàn)象,現(xiàn)在我們直接去創(chuàng)建一個(gè)測(cè)試工程,cd 進(jìn)行某個(gè)工程后,就安裝以往的方式,創(chuàng)建一個(gè)Podfile,例如:
platform:ios, '9.0'
target 'CocoaTestDemo' do
pod 'SDWebImage'
pod 'FMDB'
end
然后直接pod install,接下來神奇的一幕出現(xiàn)了....
我的終端輸出了:
Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
Downloading dependencies
Installing FMDB (2.7.5)
Installing SDWebImage (5.10.4)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `CocoaTestDemo.xcworkspace` for this project from now on.
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
這個(gè)時(shí)候我去.cocoapods目錄去查看的時(shí)候:也看到了他下載的東西
這個(gè)時(shí)候 終于結(jié)束了3天的cocoapods的安裝心酸史。淚目啊
問題分析猜測(cè)總結(jié):
1、ruby 3.0.0最新版本與cocoapods最新版不兼容,我這邊設(shè)置默認(rèn)版本后指定為了2.6.3,所以猜測(cè)至少這個(gè)版本與cocoapods兼容性最強(qiáng)。
2、因?yàn)橛玫氖亲钚碌腗1芯片處理器,所以猜測(cè)需要額外的ffi插件才能正確打開cocoapods
其他注意事項(xiàng)
1、在此次操作前 可以考慮將之前安裝的cocoapods卸載掉,包括在.cocoapods的隱藏目錄下的所有東西,我是將.cocoapods文件都刪掉了
2、在安裝好cocoapods后,先podsetup,會(huì)直接顯示podSetup completed,這個(gè)時(shí)候不需要手動(dòng)去github下載cocoapods的repo文件。