How to avoid pod install errors when building Flutter apps

There are times when pod install fails when trying to build a Flutter app on an Apple Silicon Mac, such as a MacBook Pro M1. This is when the CocoaPods installation process is executed, for example, by adding a package.

This article details how to avoid errors.

TOC

Error Description

Check the error log output by Android Studio or flutter run. The following error was found.

Launching lib/main.dart on iPhone 13 in debug mode...
Running pod install...
CocoaPods' output:
↳
      Preparing

    Analyzing dependencies

    Inspecting targets to integrate
      Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)

    Fetching external sources
    -> Fetching podspec for `Flutter` from `Flutter`
    -> Fetching podspec for `url_launcher_ios` from `.symlinks/plugins/url_launcher_ios/ios`

    Resolving dependencies of `Podfile`

Error output from CocoaPods:
↳
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `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 (arm64e))) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle (LoadError)

(Omitted due to length)

Error: To set up CocoaPods for ARM macOS, run:
  arch -x86_64 sudo gem install ffi

Error running pod install
Error launching application on iPhone 13.

To set up CocoaPods on an Apple Silicon Mac, you are instructed to do the following.

arch -x86_64 sudo gem install ffi

So we run it. It takes a little time, and ffi is installed. I run it again, but the situation has not changed.

Actually, this is obvious; it was already installed when we set up CocoaPods.

Errors are caused by differences in CPU architecture

Look at the log more closely. You will see the following output at the top.

incompatible architecture (have (x86_64), need (arm64e)))

Indeed, as per the instructions above, ffi has the x86_64 version installed; Android Studio is the native Apple Silicon version. The architecture doesn’t match, hence the error.

Check CPU architecture with Activity Monitor
Check CPU architecture with Activity Monitor

Now, what happens if we try to install the arm64 version by typing the following?

% sudo gem install ffi

Doing this will cause another error and will fail. If you try it, revert it by typing.

% arch -x86_64 sudo gem install ffi

Succeeds when via Rosetta2.

This problem only occurs on Apple Silicon Macs, not on Intel Macs. For example, pod install on a terminal running on Rosetta2 succeeds.

Manual installation on Android Studio

You can avoid the error by performing a manual installation of CocoaPods by doing the following.

STEP
Open the “Terminal” tab in Android Studio.
Open the "Terminal" tab
Open the “Terminal” tab
STEP
Go to “ios” directory.
% cd ios
STEP
Launch pod via Rosetta2.
% arch -x86_64 pod install
Analyzing dependencies
Downloading dependencies
Installing Flutter (1.0.0)
Installing url_launcher_ios (0.0.1)
Generating Pods project
Integrating client project
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
STEP
Build the application in Android Studio.

It goes ahead without error at pod install.... Since there are no changes, pod install does nothing.

Launching lib/main.dart on iPhone 13 in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                           20.3s
Debug service listening on ws://127.0.0.1:55788/_Oe8MO8SUT0=/ws
Syncing files to device iPhone 13...
Let's share this post !

Author of this article

Akira Hayashiのアバター Akira Hayashi Representative, Software Engineer

I am an application developer loves programming. This blog is a tech blog, its articles are learning notes. In my work, I mainly focus on desktop and mobile application development, but I also write technical books and teach seminars. The websites of my work and books are here -> RK Kaihatsu.

TOC