9

In my search for how Dart AOT works, I have not found many resources except this video. I would like to know how it is that code can be compiled down to native machine code, such as Android or iOS, when there exists different pieces of hardware that code needs to run on.

From what I understand, there are only descriptions of apps produced in Flutter. That description (written in Dart) is then compiled down to native machine code, but how? A program written in Swift is different from a program written in Kotlin.

Josh
  • 2,232
  • 3
  • 15
  • 33

1 Answers1

15

A compiler creates the binary code from Dart source code. For mobile applications the source code is compiled for multiple processors ARM, ARM64, x64 and for both platforms - Android and iOS. This means there are multiple resulting binary files for each supported processor and platform combination.

From what I understand, there are only descriptions of apps produced in Flutter.

Not sure what you mean by that. The concept of source code and compilation to a target platform is basically the same for each programming language. JIT (Just in Time) compiles at runtime on-the-fly while AOT (Ahead of Time) compiles before the application is deployed and launched.

A program written in Swift is different from a program written in Kotlin.

Also not sure what you mean by that. Swift can compile to native code and Java to Java bytecode. Swift is AoT while Java is JiT. The end result is always binary code for the target platform and CPU.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • The first quote: Isn't a widget just an abstract description of what the app should be? A Stateless/Stateful widget one one platform is different than another, correct? – Josh Apr 25 '18 at 04:55
  • 1
    The second quote: I'm using Flutter to make two different applications essentially, one for Swift and another for Kotlin. Are they compiled separately? – Josh Apr 25 '18 at 04:55
  • 1
    Yes, for one the Swift compiler is invoked and for the other the Kotlin compiler. The results of the compiled Dart and Kotlin or Swift are packed together in a deployable – Günter Zöchbauer Apr 25 '18 at 05:00
  • Thank you very much – Josh Apr 25 '18 at 05:10
  • 3
    You're my Dart/Flutter hero. Haha – Josh Apr 25 '18 at 05:12
  • `Swift can compile to native code and to Java bytecode.` What do you mean by this, can you elaborate? Is this a mistake? The closest resource I found to what you suggest is [this](https://www.reddit.com/r/swift/comments/lhvzxr/is_it_worth_developing_a_swift_to_jvm_bytecode/), it certainly doesn't state it's possible – Ben Butterworth Sep 13 '21 at 19:53
  • @BenButtenworth thanks for the hint. I meant "*Java* to Java bytecode" -> fixed – Günter Zöchbauer Sep 18 '21 at 10:08