CocoaPods on M1 (Apple Silicon) fails with ffi wrong architecture
Asked Answered
C

13

90

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.

Conjugated answered 15/3, 2021 at 19:20 Comment(0)
C
145

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):

  1. Uninstall Ruby with: brew uninstall ruby --force

  2. 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.

  1. 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.

Conjugated answered 23/3, 2021 at 21:38 Comment(14)
Finally i found this solution works, I tried everything, from installing new version of ruby with rbenv, updating all dependencies. Thank you :)Jacklin
Thanks, solved the problem perfectly. Very grateful!Andersonandert
Thanks, solved it perfectly for the MacBook air m1 flutter project setup.Vicentevicepresident
THIS is the solution!!! Thanks a lotSisal
brew uninstall --ignore-dependencies ruby is required instead of brew uninstall ruby --forceLycanthrope
it didn't help me on my M1Tear
This worked for me! Note: You should NOT change the arch param from -x86_64 to -arm64 (like I did) to get it working on your Apple Silicon machine.Ricard
After browsing so many threads this step finally did it for me: brew uninstall ruby --force. Thank you!Dominance
Not working, new error - Cocoapods not installed or not in valid state.Imitative
Through what black magic did you discover this was the problem? Every other day I run into issues like this where the actual root of the issue is barely related to the error given. I always just end up trawling the internet until I find a seemingly arbitrary solution.Delk
Thanks. All these steps helped. I had to change pod install to arch -x86_64 pod install to get it work on my m2. Ref: https://mcmap.net/q/245974/-pod-install-error-on-m1-mac-flutter-project-with-native-code-like-shared_preferencesNimmons
I had to completely delete rvm to get it to install correctly.Rivers
Thanks for sharing this. I have been using Roseta since 2021 and never knew a solution like this existed. It worked for meVincenzovincible
Maybe one can also consider calling gem update and bundle update afterwardsJoanejoanie
D
45

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.

Dannielledannon answered 1/6, 2021 at 20:45 Comment(8)
This is awesome, thank you for making it easier to copy and pasteFusco
For posterity for anyone trying the above and receiving the no podfile error, I ran the above excluding pod install then ran bundle install and now running smoothTlemcen
This still fails: sudo arch -x86_64 gem install ffi. Any other command to try?Zena
you save my day, but I using Mac with an M1 chip and before install rbenv 3.0.1, I following steps in #66129181Murphree
this solution didn't help me, i am using an M1Tear
This worked for me on Macbook Pro with Apple M1 Pro.Parnell
I also had to remove the Pods dir and Podfile.lockMarchal
In case you have issues with linking to openssl or gem install errors. Try installing openssl from brew and linking to it as per: github.com/rbenv/ruby-build/issues/377#issuecomment-21014365Intricacy
M
34

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)

Magnificat answered 17/10, 2021 at 11:48 Comment(4)
Thanks, This is the only solution worked for meEstate
Yes, reinstalling via brew, not gem!Hyperon
Thanks alot mate! This is the only solution worked for me also.Tove
Using homebrew to install cocoapods seems like it was the missing piece for me! Cheers!Sievert
P
19

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.

Phalanstery answered 9/2, 2022 at 14:58 Comment(0)
E
14

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

Embassy answered 27/4, 2022 at 6:33 Comment(2)
This worked for me on Mac M1Directly
Your solution work well on Mac M1 and IPhone X ios 16.2Sankaran
L
8

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
Luxe answered 5/4, 2022 at 17:57 Comment(1)
You may need to have the path to pod. echo 'export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.1.0/bin/:$PATH"' >> ~/.zshrc. ruby version may vary.Solitta
G
6

When i tried the x86_64:

sudo arch -x86_64 gem install ffi

linking shared-object ffi_c.bundle
ld: warning: ignoring file /Users/aa/.rbenv/versions/3.0.1/lib/libruby.3.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_rb_ary_detransient", referenced from:
      _memory_put_array_of_int8 in AbstractMemory.o

so I tried:

sudo arch -arm64e gem install ffi

sudo arch -arm64e gem install cocoapods

then pod install worked!

I also had to run rbenv init and place the eval in ~/.zshrc to get the right ruby version working.

Glasswork answered 20/10, 2022 at 20:56 Comment(1)
I think this is the best solution. Every other solution forced me to eventually have to use arch -x86_64 pod install again rather than pod install.Inpour
J
5

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
Jessie answered 17/2, 2022 at 11:27 Comment(2)
This worked for me: 1. sudo arch -arm64e gem install cocoapods 2. sudo arch -arm64e gem install ffiStruma
I tried everything and only this worked thanks @Jessie !Nekton
J
4

All I did for my case was run the following command to pod install. I didn't have to uninstall ruby or cocoapod

arch -x86_64 pod install

Juarez answered 9/9, 2022 at 10:41 Comment(1)
Indeed, just type: arch -x86_64 pod installBough
S
2

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
Sheronsherourd answered 22/11, 2021 at 20:48 Comment(0)
C
1

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://mcmap.net/q/245976/-please-install-libyaml-and-reinstall-your-ruby

Castellatus answered 14/1, 2022 at 17:40 Comment(0)
S
0

just run this code, already fix

brew uninstall --ignore-dependencies ruby
Sibel answered 23/6, 2022 at 14:48 Comment(0)
E
0

For an error: incompatible architecture (have 'x86_64', need 'arm64'), you need to do the following:

  1. gem list --local | grep cocoapods | awk '{print $1}' | xargs sudo gem uninstall

  2. sudo gem install ffi

  3. sudo gem install cocoapods

Eliseoelish answered 7/2 at 11:30 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Botanomancy

© 2022 - 2024 — McMap. All rights reserved.