Android Compilation Process

How your device understand Java Code?

Your source code is compiled by Standard Java Compiler which uses the JIT- ‘Just-In-Time’ compilation model.

Once the code is compiled, it becomes bytecode (with ‘.class’ extension). This code goes for a second round of compilation (Again to Bytecode – But this time it is minimized).

The bytecode gets executed by target-specific-JVM (Java Virtual Machine) which is a runtime environment for Java.

Android Compilation:

In Android,we have two different virtual machine.

  1. Dalvik
  2. ART
1. Dalvik:

It uses JIT Compilation model.
JIT compiler compiles the app when they are opened by users.So it made opening of app slower.

2. ART:

ART uses the ahead-of-time compilation model which compiles the apps to machine code upon installation.
Installation process is slow with ART as apps to machine code conversion taks time.
ART is released in Android 4.4 (Kitkat).

android-kitkat-introduces-art

Android Compilation Process:

the-android-compilation-process

Source Code to ByteCode

You need JDK to compile the Java code of application.
Code and precompiled Class from third party libraries are first compiled by Javac.
Javac Outputs set of Java Byte code file.

ByteCode to Minimized Byte Code

This Step is Optional.
By default Proguard is disabled.
Proguard tool takes byte code as input and it will minimize and Remove unclear,unintelligible code.

Minimized Byte Code to Dex Byte Code

It will convert Minimized Byte Code to Dex Byte Code(Dalvik Executable – .DEX)
Dex Byte Code is optimized for Android and which can be executed by either Dalvik or ART

Dex Byte Code to Machine Code

Device’s runtime read those dex files,then convert to machine code.
On Dalvik,this step happens as the app runs using JIT
On ART,this step happens when the app is first installed.App will run faster when user starts using the app.

Advertisements