Setting up the iOS Development Environment for the new MacBook Pro M1 with ease

Rémon Helmond
Hackberry
Published in
4 min readJan 21, 2021

I recently received the new MacBook Pro with Apple’s new M1 chip.
When setting up my dev environment for Flutter, I ran into some problems with building my app for iOS.

It took me some time to figure out how to successfully develop, build and run an app without any problems. I am certain that future developers, who make the switch to devices with the M1 chip, might run into similar problems. This articles explains how to overcome the issues.

What was the issue?

At the time of writing the CocoaPods is not officially supported on devices with Apple’s M1 chip.

This results in the following error message when trying to install the dev dependencies using the pod install command:

LoadError — dlopen(/Users/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/ffi-1.14.2/lib/ffi_c.bundle, 9): no suitable image found. Did find:/Users/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/ffi-1.14.2/lib/ffi_c.bundle: mach-o, but wrong architecture/Users/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/ffi-1.14.2/lib/ffi_c.bundle: mach-o, but wrong architecture — /Users/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/ffi-1.14.2/lib/ffi_c.bundle

The reason behind this error is incompatibility of the Ruby gem library ffi with Apple’s new silicon and my ruby environment did not use the Rosetta emulation.

Apple provides Rosetta 2 (official docs) a bridge for the transition from Intel to the new Apple processors. It translates software built for Intel and makes them run on ARM processors like the M1.

This incompatibility and it’s related issue in combination with CocoaPods and Apple Silicon is already known and actively worked on (see raised issue on GitHub)

How to fix it

  • Install Rosetta 2 on your Macbook.
$ softwareupdate — install-rosetta 
  • Enable Rosetta mode for terminal app

Open ‘Applications’ in your Finder, search for the terminal application, open its information using right-click and selecting ‘Get Info’.

In the General section enable the “Open using Rosetta” checkbox.

  • Recommendation: Have two terminals, one with Rosetta and one without it

This step is not needed per se, but it can be useful to have two terminals, where one is operating using the Rosetta emulation mode and the other one in “normal” mode.

Enable Rosetta for Terminal Application

Install CocoaPods + Ruby

CocoaPods is using Ruby and it is a good rule of thumb to not use the system ruby version.

Therefore, I choose to set up Ruby using homebrew and rbenv. Feel free to use any method you like.

The most important part is that all commands are executed in a terminal where Rosetta is enabled.

  • Install homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh"
  • Once the installation is complete, use brew to install rbenv
$ brew install rbenv
  • The next step is to install a version of Ruby
$ rbenv install 2.7.2

Note: There are some issues with Ruby version 2.6.6 when your Apple device has an M1 chip, so it is better to use version 2.7.2.
(Have a cup of coffee, because the installation of Ruby will take a while).

Also do not forget to run:

$ eval "$(rbenv init -)"

or even better, add it to your bash profile!

  • Set the Ruby version for your current project

Navigate to the folder where your project is located and change the Ruby version to the version you installed using the following command:

$ rbenv local 2.7.2 .
  • Make sure to install two gems ffi (a dependendy by CocoaPods) and cocoapods.
$ gem install ffi 
$ gem install cocoapods

That is it, your Ruby environment is properly configured! 🎉

Now you can run pod install in your project without any issue.

Next issue: Running iOS simulators

Finally all dependencies are installed but when trying to run your app using an iOS Simulator the following error occurs:

ld: building for iOS Simulator, but linking in dylib built for iOS, file ‘/Users/user/development/myapp/ios/Flutter/Flutter.framework/Flutter’ for architecture arm64clang: error: linker command failed with exit code 1 (use -v to see invocation)

Luckily this issue is also easily fixed: The trick is to exclude the simulators and SDK for arm64 -based architecture.

In Xcode, go to your workspace Runner, select ‘Build Settings’ section and search for the ‘Architectures’ category. Here, exclude the arm64 architecture like shown on the screenshot below.

That’s it you are all set! 🎉

Happy Coding! 💻📱

--

--

Rémon Helmond
Hackberry

I am an app developer that loves to study and write about leadership, self development and everything tech. Besides that I am a keen sportsman.