How Kotlin code runs on Android

Kotlin language Junior Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Order the steps

Put the steps from Kotlin source to running code in order.

  • D8/R8 converts bytecode to DEX and shrinks it
  • kotlinc compiles .kt files to JVM bytecode
  • ART runs the DEX, compiling hot code with profiles
  • The APK or AAB is installed

Choose an answer, then open Show answer below to check it.

Show answer

Answer: B A D C

  1. kotlinc compiles .kt files to JVM bytecode Kotlin's compiler targets JVM bytecode for Android.
  2. D8/R8 converts bytecode to DEX and shrinks it DEX is the format ART runs.
  3. The APK or AAB is installed DEX files are packaged with resources.
  4. ART runs the DEX, compiling hot code with profiles Interpretation, JIT and AOT, guided by profiles.

30-second answer

The Kotlin compiler turns source into JVM bytecode (.class files). The Android build then converts that bytecode to DEX with D8, shrinks and optimises it with R8, and packages it into the APK or bundle. On the device, the Android Runtime (ART) runs the DEX code using a mix of interpretation, JIT and ahead-of-time compilation. There's no Java Virtual Machine on the phone.

Practise saying it · 35 s. No recording, just a timer

Explain how Kotlin runs on Android.

Say your answer out loud, then check which of these points you covered:

  • kotlinc to bytecode
  • D8/R8 to DEX
  • ART runs DEX
  • No JVM on the device
  • Baseline Profiles guide AOT

Deep dive

Java and Kotlin interoperate because both compile to the same bytecode before DEX conversion.

Baseline Profiles tell ART which methods to compile ahead of time at install, speeding up startup.

Library desugaring lets you use newer Java APIs like java.time on older Android versions.

Kotlin Multiplatform can also compile the same Kotlin to native code (iOS) or JavaScript/Wasm.

Common mistakes

  • Saying Android runs Kotlin on the JVM.
  • Thinking Kotlin compiles directly to DEX.
  • Confusing R8 (shrinking/optimising) with D8 (dexing).

Senior take & follow-ups

Walk the pipeline in one breath: kotlinc, bytecode, D8/R8, DEX, ART with profiles.

Follow-up questions

Think of your answer first, then open the hint.

  1. What does R8 do?

    Show hint

    Shrinks, optimises and obfuscates code, and produces DEX in release builds.

  2. What are Baseline Profiles?

    Show hint

    Lists of hot code that ART compiles ahead of time.

Suggest a fix if something here is wrong or out of date.