About Android Runtime (ART)

Eric Lee
3 min readMar 6, 2021

It’s a summary of the study. If there is wrong information, please let me know it.

Android runtime(ART) is a kind of runtime environment and it’s for an Android operating system. It has been fully introduced since Lollipop(5.0/API 20). Let’s compare and organize what the differences and benefits are step by step.

The following picture is the whole process from how to build an app, to run the app on a device. If you need a background of that, I recommend you follow the link under the picture.

https://en.wikipedia.org/wiki/Android_Runtime

About the build process for APK

The source code is compiled by java compiler to java bytecode. The format is .class and we call multiple *.class as a jar. The java bytecode needs to be converted as .dex format for Dalvik virtual machine(DVM), so dex compiler does it. Additionally more processes like proguard, R8 and signing are passed, we can output an apk file.

The above process can be reversed logically. Apk format is a kind of zip format, so you can unzip it. Then you can find the .dex file and you can convert it to jar because .dex and .class are isomorphic. Finally, you can see the code through the jd-gui tool. If you use this, you can reverse apk to the source, including deobfuscator at once.

About Dalvik

The Dalvik is process virtual machine. It is register-based and specific for Android mobile devices. It is optimized for using memory and supports process isolation. It’s not Java virtual machine. So java bytecode can’t run on DVM. It needs an exclusive use bytecode that is called Dex.

Just in time (JIT)

It was added at Froyo(2.2/API 8). It compiles bytecode into native machine code at runtime, but it runs every time. Furthermore, there are more things but I’ll omit them.

dexopt

It creates an optimized dex file that is called Odex.

About ART

Just to make it simple, it replaces JIT with AOT. Dex still is used. But Odex is replaced by OAT. In conclusion, it achieves battery saving and better performance over Dalvik. Plus, Dalvik can't get an advantage on 64-bit architecture. Because it's based on 32-bit architecture. But, ART can get benefits.

Ahead of time (AOT)

It converts the whole application to native machine code at install time. Thus it uses more storage and memory but the converting occurs only once.

dex2oat

It creates anOAT file that can be executed as Executable and Linkable Format(ELF) at install time only once. Also, the bytecode can be run by a processor instead of a virtual machine. OAT file structure depends on the version of Android. The latest Android OAT format for Android Oreo(8.0 /API 26) is this.

Executable and Linkable format (ELF)

OAT files are actually embedded in ELF object files. Thus it can be run on any processor or architecture. If you need the information, then use thereadelf tool.

Reference

--

--