M1のMacにCOCOAPODSを入れる方法の解説記事です。M1だとPOD INSTALLやPOD UPDATEでコケるようです。COCOAPODSのインストールにコツがあります。
COCOAPODSのインストールで早速怒られる
sudo arch -x86_64 gem install cocoapods
sudo arch -x86_64 gem install ffi
すると怒られました。
ERROR: Error installing cocoapods:
The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.3. Try installing it with `gem install activesupport -v 6.1.7.3` and then running the current command again
activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
言われた通りにACTIVESUPPORTを入れてみる
sudo gem install activesupport -v 6.1.7.3
pod setup
コマンドでCocoaPodsの環境をセットアップします。
pod setup
うまくいきます。
POD UPDATEでコケる
ではGITから何かサンプルコードを持ってきてPOD UPDATEしてみます。
pod update
`require’: dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle, 0x0009): tried: ‘/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle’ (mach-o file, but is an incompatible architecture (have ‘x86_64’, need ‘arm64’)), ‘/System/Volumes/Preboot/Cryptexes/OS/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle’ (no such file), ‘/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle’ (mach-o file, but is an incompatible architecture (have ‘x86_64’, need ‘arm64’)) – /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle (LoadError)
こけました。ARM関連のエラーのようです。
以下のコマンドを打ってみました。
gem install --user-install ffi -- --enable-libffi-alloc
するとPOD UPDATEも機能しました。
参考資料
以下を参考にしました。