'CocoaPods on M1 (Apple Silicon) fails with ffi wrong architecture
Running 'pod install' on a M1 MacBook failed for me due to an ffi issue, as described here.
I followed some of the workarounds (I guess I tried all of them in various order), but now I get a slightly different error:
LoadError - dlopen(/opt/homebrew/lib/ruby/gems/3.0.0/gems/ffi-1.15.0/lib/ffi_c.bundle, 9): no suitable image found. Did find:
/opt/homebrew/lib/ruby/gems/3.0.0/gems/ffi-1.15.0/lib/ffi_c.bundle: mach-o, but wrong architecture
/opt/homebrew/lib/ruby/gems/3.0.0/gems/ffi-1.15.0/lib/ffi_c.bundle: mach-o, but wrong architecture - /opt/homebrew/lib/ruby/gems/3.0.0/gems/ffi-1.15.0/lib/ffi_c.bundle
So, it seems I now have ffi, but with a wrong architecture? How can I fix this? This happens with/without running the terminal in Rosetta mode.
One of the proposed workarounds did not succeed for me, by the way. When I try:
sudo arch -x86_64 gem install ffi
I get:
arch: posix_spawnp: gem: Bad CPU type in executable
Not sure if this is related.
Solution 1:[1]
Answering my own question. I fixed the ffi issue by uninstalling my faulty Ruby version and CocoaPods, then I used the -x86_64 arch to reinstall ffi and CocoaPods.
These are the steps I did to get back to a working state (and to apply the M1 workarounds for ffi):
Uninstall Ruby with:
brew uninstall ruby --force
Uninstall CocoaPods. At first, try to list all CocoaPods versions / components with
gem list --local | grep cocoapods
. Then uninstall them one by one, in my case:
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-downloader
etc.
- As a next step I was able to reinstall ffi and then CocoaPods with:
sudo arch -x86_64 gem install ffi
sudo arch -x86_64 gem install cocoapods
Once done, I could run pod install
as expected. Note that I had the Terminal open all the time in standard mode - no Rosetta required.
Solution 2:[2]
As said Datasun I removed cocoapods
gem list --local | grep cocoapods | awk '{print $1}' | xargs sudo gem uninstall
and then run:
brew remove rbenv
sudo rm -rf ~/.rbenv
sudo arch -x86_64 gem install ffi
sudo arch -x86_64 gem install cocoapods
brew install rbenv
rbenv install 3.0.1
rbenv global 3.0.1
pod install
without any problem.
Solution 3:[3]
I agree with Datasun's answer. But I managed to follow roughly the same steps which gave a a functioning outcome, that I thought to be better or just as good. I ran the lines in terminal:
brew uninstall --ignore-dependencies ruby
then
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-downloader
after this I wanted to Homebrew the cocoapods so I used:
brew install cocoapods
(you may need to use reinstall)
Solution 4:[4]
I tried almost everything and this was the only solution that worked for me:
uninstalling the cocoapods package through gem (sudo gem uninstall cocoapods)
and reinstalling it with homebrew (brew install cocoapods) fixed my problem.
The problem was I installed cocoapods
through gem install instead of homebrew.
Solution 5:[5]
I got this error while setting up capacitor project on my new macbook with m1 chip. However, if you want to use capacitor, flutter or React Native, you will get this error because this is a framework independent, computer-related problem.
Ruby and cocoapods must be installed on your computer. In my case, running the following commands one by one worked.
1.
brew install ruby
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
brew install cocoapods
and, you are ready now.
pod install
Solution 6:[6]
For me, I had to do these extra things after following @Datasun:
brew install ruby
and
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
Solution 7:[7]
I got it working by first cleaning up all previously installed pods:
pod deintegrate
Then installing them again using this command:
arch -x86_64 pod install
Solution 8:[8]
This described the exact problem that I was having. However, none of the solutions worked. In the end, this is what helped me solve the problem:
brew unlink libyaml && brew link libyaml
brew unlink openssl && brew link --force openssl
Reference: https://stackoverflow.com/a/24902917/1809053
Solution 9:[9]
I agree with Datasun's answer. But currently we can use arm64
instead of x86_64
in M1 Macbook.
I reinstall ruby
and ran the lines in terminal:
gem uninstall cocoapods
gem uninstall cocoapods-core
gem uninstall cocoapods-downloader
gem uninstall ffi
gem install ffi
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow