How to run CocoaPods on Apple Silicon (M1)
#1
I have encountered an issue with CocoaPods installation on my M1 Mac when trying to run a Flutter project that works without any problems on an Intel-based Mac. It appears the pods installation is failing due to a `LoadError` that mentions a missing symbol in the `ffi_c.bundle`. The stack trace indicates a problem with the `ffi` gem, which is a Ruby native extension used for interfacing with C libraries. The full error message is below.
Here's the problematic part of the stack trace:

Code:
...[omitted
        for brevity
    ] /
    Library / Ruby / Gems / 2.6 .0 / gems / cocoapods - 1.10 .0 / bin / pod: 55: in `<top (required)>'
/usr/local/bin/pod:23:in `
load ' /
    usr / local / bin / pod: 23: in `<main>'

Despite following a workaround that suggests running the Terminal using Rosetta, I'm still facing the same issue. Given that M1 support is still in development, has anyone successfully managed to resolve this?
Reply
#2
From what you're describing, it sounds like the gem is not compatible with ARM architecture. One of the things you can try is to update your `ffi` gem. This can sometimes resolve issues with native extensions. You should also make sure to run the `pod install` command under an architecture that the gem supports, which could be possible via Rosetta. You can set the terminal to run with Rosetta by default or prefix commands to execute under the Intel architecture emulation. Here's how you can update the gem:

Code:
sudo gem install ffi

Once that's done, you could try running the `pod install` command again. If it still doesn't work, you might also want to consider setting up a Ruby version manager, like `rbenv` or `rvm`, and then installing a version of Ruby that is compatible with your system architecture.
Reply
#3
It's also possible that you're using the system Ruby which comes with macOS. This might not play well with the newer architecture. I would recommend using `rbenv` to install a separate version of Ruby tailored for the M1 chip. Make sure you're also running the terminal natively and not under Rosetta if you're using an ARM-compatible Ruby version. You can do this by installing `rbenv` and a new Ruby version:


After installing Ruby via `rbenv`, you should install the `cocoapods` gem and attempt to run `pod install` again to see if the issue persists. Make sure you restart the terminal or run `rbenv rehash` for changes to take effect.
Reply
#4
I ran into a similar problem recently and can confirm that updating the `ffi` gem alone didn't work for me. Instead, I had to completely reset my CocoaPods setup after ensuring I was using a compatible version of Ruby. This included uninstalling the `cocoapods` gem, reinstalling it, and then updating all pods. Here's a list of commands that worked for me:

Code:
sudo gem uninstall cocoapods
sudo gem install cocoapods
pod setup
pod install

Remember that using `sudo` with gem commands can introduce permission complexities, so it's often better to manage Ruby environments with `rbenv` or `rvm`. These allow for a more isolated and manageable Ruby setup that can prevent many of these kinds of problems.
Reply
#5
Thank you all for the input. After trying the different approaches, I found that reinstalling Ruby with `rbenv` and then reinstalling CocoaPods made the installation work. Here are the steps I followed for anyone else facing the issue:

Code:
# Install CocoaPods
gem install cocoapods
# Navigate to your Flutter project 's iOS folder, then run
pod install

After these steps, my Flutter project was able to run on the iOS simulator without any CocoaPods-related issues on my M1 Mac. Make sure to open a new terminal session or run `rbenv rehash` after installation to refresh the environment paths.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)