How Android Code İs Compiled?

Burhan ARAS
Jul 4, 2017 · 2 min read

Although, we use Java when developing Android apps, there are many differences between traditional Java SE and the way we code Android.

The virtual machine that runs on an Android device is called Dalvik Virtual Machine(DVM). Maybe the most significant difference between the both is that JVM is stack-based while DVM is register-based.

One minute! What the hell is stack based and register based?

Ok, let me briefly explain:

In Stack Based VM’s, all the arithmetic and logic operations are carried out via Push and Pop operands and results in the stack.

On the other hand, in Register Based VM’s, the data structure where the operands are stored is based on the registers of CPU.

Java code is compiled to an intermediate format called byte-code. Then this byte-code is parsed by JVM and translated to machine code.

Android SDK has a tool called dx that converts Java byte-code to Dalvik byte-code. It is locates under build-tools/android-{version}.

Then Dalvik VM moves in and translates Dalvik byte-code to binary machine code.

Finally, i have visualised the different flows with my own handwriting.

In next article, we will answer that how an app is started in Android.

Until then, have fun!

Effective Android Engineer

Premature optimisation is the root of all evil

Burhan ARAS

Written by

Software Engineer

Effective Android Engineer

Premature optimisation is the root of all evil

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade