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.
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.
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.
% cd ios
% 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.
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...