Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Dart/Flutter get compiled to Android?

I can't find any concrete resources on this, does Dart get compiled to JVM, or did the Google's team compile the Dart VM to be run on the JVM and then run Dart inside Dart VM inside JVM?

The former makes more sense and it goes inline with the "no bridge" mantra, but the latter seems more inline with how integration between native & flutter code looks like

like image 225
bbozo Avatar asked Jan 27 '19 14:01

bbozo


1 Answers

Dart is compiled to native machine code (ARM, Intel, ...) executable and bundled with some native platform code (Java, Kotlin, Objective-C/Swift) to interact with the native platform.

See also

How does Flutter run my code on Android? The engine’s C and C++ code

are compiled with Android’s NDK. The Dart code (both the SDK’s and yours) are ahead-of-time (AOT) compiled into a native, ARM library. That library is included in a “runner” Android project, and the whole thing is built into an APK. When launched, the app loads the Flutter library. Any rendering, input or event handling, and so on, are delegated to the compiled Flutter and app code. This is similar to the way many game engines work.

Debug mode builds use a virtual machine (VM) to run Dart code (hence the “debug” banner they show to remind people that they’re slightly slower) in order to enable stateful hot reload.

How does Flutter run my code on iOS? The engine’s C and C++ code are

compiled with LLVM. The Dart code (both the SDK’s and yours) are ahead-of-time (AOT) compiled into a native, ARM library. That library is included in a “runner” iOS project, and the whole thing is built into an .ipa. When launched, the app loads the Flutter library. Any rendering, input or event handling, and so on, are delegated to the compiled Flutter and app code. This is similar to the way many game engines work.

Debug mode builds use a virtual machine (VM) to run Dart code (hence the “debug” banner they show to remind people that they’re slightly slower) in order to enable stateful hot reload.

https://flutter.io/docs/resources/faq#how-does-flutter-run-my-code-on-android

See also https://proandroiddev.com/flutters-compilation-patterns-24e139d14177

like image 179
Günter Zöchbauer Avatar answered Oct 09 '22 09:10

Günter Zöchbauer