How to avoid pod install errors when building Flutter apps

At times, when building a Flutter app on an Apple Silicon Mac, like a MacBook Pro M1, you may encounter failure during pod install. This is when the CocoaPods installation process is executed, for example, by adding a package.

This article provides detailed steps to avoid these errors.

TOC

Error Description

Check the error log output by Android Studio or flutter run. For example, 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 execute the command. After a brief delay, ffi gets installed. However, upon rerunning it, the situation remains unchanged.

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; However, 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

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 issue is specific to Apple Silicon Macs and does not occur on Intel Macs. So, for example, pod install on a terminal running on Rosetta2 succeeds.

Manual installation on Android Studio

You can avoid the error by manually installing CocoaPods by doing the following.

STEP
Open the “Terminal” tab in Android Studio.
Open the "Terminal" tab
Open the “Terminal” tab
STEP
Go to the “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.

The process proceeds without encountering an 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...

Authored Books

Let's share this post !

Author of this article

Akira Hayashi (林 晃)のアバター Akira Hayashi (林 晃) Representative(代表), Software Engineer(ソフトウェアエンジニア)

アールケー開発代表。Appleプラットフォーム向けの開発を専門としているソフトウェアエンジニア。ソフトウェアの受託開発、技術書執筆、技術指導・セミナー講師。note, Medium, LinkedIn
-
Representative of RK Kaihatsu. Software Engineer Specializing in Development for the Apple Platform. Specializing in contract software development, technical writing, and serving as a tech workshop lecturer. note, Medium, LinkedIn

TOC