What I want?
Building universal apps for iOS, Android, Windows, MacOS, Linux using Flutter on a M1 Mac.
This is very new and latest. I can’t guarantee you can make it at 100%.
There’s no official support since Apple silicon is still new in coding world.
Their full tutorial is here: https://flutter.dev/docs/get-started/install/macos
Here i only address some issues i met.
what we need?
1. Android studio preview 2021.1.1 Canery 3 (latest which supports m1)
2. flutter 2 SDK (latest stable version)
3. java sdk ( openjdk 11 from zulu built for macos arm64)
4. cocoapods ( Open your Terminal.app with Rosetta 2 )
Step 1 is very easy.
and download the one for m1 mac.
when you open the android studio, don’t forget to install all the SDK you need. Here is one important tool. Android SDK command-line Tools
Install the Flutter 2.
go here: https://flutter.dev/docs/get-started/install/macos
Very easy just follow the steps.
I need to build apps for desktop so i enabled this(you don’t have to, this is optional if you only want to build apps for iOS and Android): https://flutter.dev/desktop
Then use commands
flutter doctor -v
to check your system
I had this issue with my Android Studio Preview
Android Toolchains. Install all the SDK that you need when you open the Android Studio Preview for the first time.
Xcode. Install Xcode from Apps Store and install xcode command lines. Just wait by several clicks.
cocoapods. Copy and paste a new Terminal.app to desktop and open it using Rosetta 2 like this.
Then in the rosetta 2 terminal, install cocoapods by commands
sudo gem install cocoapods
Ruby 2 is installed on MacOS 11 by default but its fii lib is still built on top of x86_64 architecture though Apple claimed Ruby 2 on MacOS 11 is for 2 architectures such as x86_64 and ARM64, which is a lie.
If you simply install cocoapods using the ARM64 version of ruby 2 on MacOS 11, you will fail to load the fii libs. fii is a lib which can talk to native c libs on macos, we need it so much.
More info https://www.jianshu.com/p/eb74b392a661
Android studio: Unable to find bundled java version.
in source codes, flutter/packages/flutter_tools/lib/src/android/android_studio.dart Line 465 in 3c72ef3 globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') : There should be check for join(directory, 'jre', 'Contents', 'Home') instead of join(directory, 'jre', 'jdk', 'Contents', 'Home') for newest android studio previews (at least on macos). Workaround for such people: copy folder /Applications/Android Studio Preview.app/Contents/jre/Contents to /Applications/Android Studio Preview.app/Contents/jre/jdk/Contents
Just copy the folder Contents to a new folder jdk inside of the main app. (This is a bug which would be fixed in the future)
Then go back to my normal terminal which is ARM64 native and do the doctor check.
create a hello world using flutter on macos, ios app
follow this step. https://flutter.dev/docs/get-started/install/macos
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch
sudo xcodebuild -license # agree all licenses
Set up the iOS simulator
open -a Simulator
Create and run a simple Flutter app
flutter create my_app cd my_app flutter run
this is the debugger
If you want to debug apps on a physical iPhone, you would need to iproxy from flutter to pass the debug info. In MacOS 11 , go system preferences, security & privacy, unlock the button, and click allow iproxy to run. Info from here: https://github.com/flutter/flutter/issues/42969#issuecomment-772211836
DON’T forget a GOOD QUALITY USB Cable for iPhone.
we can use android studio to create arm64 android VM, and use adb (comes from the android studio) to install apk for debugging (in Flutter/Dart or Java or Kotlin)
Start the Android emulator, install the apk manually
$ emulator -list-avds Pixel_2_API_30 # start the emulator $ emulator -avd Pixel_2_API_30 # install apk to the emulator adb install /path/to/some.apk
or you can use the android studio to debug the apk