Android and Desktop app Kotlin compilation process comparisons - Java Virtual machine(JVM), Dalvik Virtual Machine(DVM) and Android Runtime(ART)
Have you ever wondered what happens when you compile your Kotlin source code?
The Kotlin Compiler doesn't convert your code to machine code directly, but it converts your code to bytecode instead.
Then, the Kotlin Interpreter/Virtual Machine converts the bytecode to machine code during run-time/installation time.
Java Virtual Machine (JVM)
In the desktop app, the Kotlin interpreter is called Java Virtual machine (JVM).
The JVM compiles the Java bytecode(*.class) to machine code when the app is launched. This is called the Just-in-time (JIT) compilation.
Dalvik Virtual Machine (DVM)
In the Android app, the Kotlin Interpreter is called Dalvik Virtual Machine (DVM). It is similar to JVM except it doesn't read in Java Bytecode but Dalvik bytecode.
So there is one additional layer where the DEX Compiler (DX) compiles the Java bytecode into Dalvik bytecode(*.dex).
Then, Dalvik Virtual Machine (DVM) compiles the Dalvik bytecode into machine code when the app is launched. So the DVM is also a Just-in-time compilation.
Android Runtime (ART)
After Android KitKat / Version 4.4 / API Level 19 was introduced in 2013, the Dalvik Virtual Machine (DVM) is replaced by Android Runtime(ART).
ART is similar to DVM except it compiles the Dalvik bytecode to machine code during app installation.
This is called the Ahead-of-time compilation. The benefit is it runs faster during app launching at the expense of executable file size.
Conclusion
Well, this is just a high-level diagram to show the Android app compilation process. I was not completely aware of this compilation process before, which I believe is a super important concept for all Android app developers to understand.
For more details about ART (which you don't need to know), you can refer to the official documentation here.
Originally published at https://vtsen.hashnode.dev.
Top comments (0)