Dart SDK officially supports ARM64 and as of now, 2.14.2 is the latest (stable) Dart SDK that has support for ARM64. Though it was the same version that was bundled in my Flutter setup, it seemed to run on Intel architecture (Activity monitor shows dart processes running on Intel).
I manually tried replacing the dart SDK on my flutter installation bu replacing flutter-directory/bin/cache/dart-sdk/
with the contents of a zip file of the Dart SDK made for ARM64, downloaded from dart.dev archive. But trying to run an app on an Android emulator (which runs on ARM64 and was working on my old Flutter setup), throws this error:
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
lib/main.dart:1
Snapshot not compatible with the current VM configuration: the snapshot requires 'release no-code_comments
no-dwarf_stack_traces_mode lazy_async_stacks lazy_dispatchers
use_bare_instructions no-dedup_instructions
no-"asserts" "use_field_guards" "use_osr" x64-sysv no-null-safety' but the VM has 'release no-code_comments no-
dwarf_stack_traces_mode lazy_async_stacks
lazy_dispatchers use_bare_instructions no-dedup_instructions no-"asserts" "use_field_guards" "use_osr" arm64-sysv no-null-safety'
2
the Dart compiler exited unexpectedly.
Is there any other way to do a completely ARM64 Flutter setup on M1 devices?
Flutter version 2.5.1
Dart version 2.14.2
Device: MacBook Air (M1, 2020)
If you're developing Flutter apps, then you don't need to separately download the Dart SDK; just install Flutter. To learn about other tools you can use for Dart development, see the Dart tools page.
Note: The Flutter SDK includes the full Dart SDK, and has Dart's dart command-line interface in its bin folder. Dart tools may send usage metrics and crash reports to Google.
Downloading the Flutter SDK also downloads the compatible version of Dart, but if you’ve downloaded the Dart SDK separately, make sure that the Flutter version of dart is first in your path, as the two versions might not be compatible.
The current Dart SDK version is 2.10.4. how can I change the version into a upper version .? In a beta or dev channel How to change the current Dart SDK version? How to replace the bundled Dart SDK in Flutter to run natively on Apple Silicon (ARM64)?
Not sure about dart is in bin/dart so take a look at dart directory to see if there is no system files in that if not then delete it and delete whole flutter folder that's all make sure .zshrc is also deleted there's no path given, restart once and install flutter again
At March 4 2021, Flutter 2.0 is release as stable version. But if you have still have old projects that haven’t support yet for Flutter SDK v2.0+ and you also have some project that you want to try with Fluter SDK 2.0+. You may need to switch between Flutter SDK v1.+ and v2.0+.
Update: Starting with Flutter 3.0, Flutter ships with arm64 dart sdk, so all you have to do is update to the latest version
Old answer:
dart-sdk
folderflutter-sdk-root/bin/cache
dart-sdk
from the previous step with the one you've downloadedNow, this part is hacky, so I can't really guarantee it will always work.
If you try to run the app now, dart compiler will crash.
Using flutter run -v
(which enables verbose mode, for more logs) and thanks to a couple of google lookups I was able to figure out that the problem is caused by a snapshot file called frontend_server.dart.snapshot
which is located in 2 places in the sdk:
flutter/bin/cache/dart-sdk/bin/snapshots
- new snapshot that targets arm, you've just pasted it hereflutter/bin/cache/artifacts/engine/darwin-x64
- old snapshot still for x64
frontend_server.dart.snapshot
from the first path mentioned above to the second path, replacing the old fileI've run a very casual test to give me a feeling if there's any improvement in compile time of a hello world app. By casual I mean I didn't close any programs that were in the background.
The process of the test was like following:
And the initial results are pretty promising:
$ dart --version
Dart SDK version: 2.15.0-116.0.dev (dev) (Thu Sep 16 09:47:01 2021 -0700) on "macos_arm64"
$ flutter --version
Flutter 2.6.0-11.0.pre • channel dev • https://github.com/flutter/flutter.git
Framework • revision 4b330ddbed (5 weeks ago) • 2021-09-16 17:29:58 -0700
Engine • revision 5b81c6d615
Tools • Dart 2.15.0 (build 2.15.0-116.0.dev)
Update: As of Flutter 3.0.0, the arm64 dart sdk is used by default. The patcher can still be used for older versions if necessary.
Using the other answers here, I created flutter_m1_patcher.
It gets the version of Flutter's bundled Dart SDK and replaces it with the arm64 version.
It seems it can't be used with Flutter yet, as seen in:
Apple Silicon support in the Dart SDK
[...] Note that the Dart SDK bundled in the Flutter SDK doesn’t have these improvements yet.
https://medium.com/dartlang/announcing-dart-2-14-b48b9bb2fb67
[Announcing Dart 2.14][ScreenShot]: https://i.stack.imgur.com/N8Qcc.png
And:
Get the Dart SDK
[...] As of Flutter 1.21, the Flutter SDK includes the full Dart SDK. So if you have Flutter installed, you might not need to explicitly download the Dart SDK. Consider downloading the Dart SDK if any of the following are true:
- You don’t use Flutter.
- You use a pre-1.21 version of Flutter.
- You want to reduce disk space requirements or download time, and your use case doesn’t require Flutter. For example, you might have a continuous integration (CI) setup that requires Dart but not Flutter.
https://dart.dev/get-dart
[Get the Dart SDK][ScreenShot]: https://i.stack.imgur.com/rawJV.png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With