The Android runtime (ART) is the heart of Android. It’s a fast, ahead-of-time compiled runtime with modern garbage collection designed to scale. Android applications are compiled to Dalvik bytecode and run with ART. This section includes detailed information such as the Dalvik Executable format specification, and design information on the runtime itself.

The Android runtime (ART) is the default runtime for devices running Android 5.0 (API level 21) and higher. This runtime offers a number of features that improve performance and smoothness of the Android platform and apps.

  1. Addressing Garbage Collection (GC) Issues
  2. Preventing JNI Issues
  3. Checking JNI code for garbage-collection issues
  4. Error handling
  5. Object model changes
  6. Preventing Stack Size Issues
  7. Fixing AOT Compilation Issues
  8. Reporting Problems

How ART works

ART uses ahead-of-time (AOT) compilation, and starting in Android 7.0 (Nougat or N), it uses a hybrid combination of AOT, just-in-time (JIT) compilation, and profile-guided compilation. The combination of all these compilation modes is configurable and will be discussed in this section. As an example, Pixel devices are configured with the following compilation flow:

  1. An application is initially installed without any AOT compilation. The first few times the application runs, it will be interpreted, and methods frequently executed will be JIT compiled.
  2. When the device is idle and charging, a compilation daemon runs to AOT-compile frequently used code based on a profile generated during the first runs.
  3. The next restart of an application will use the profile-guided code and avoid doing JIT compilation at runtime for methods already compiled. Methods that get JIT-compiled during the new runs will be added to the profile, which will then be picked up by the compilation daemon.

ART comprises a compiler (the dex2oat tool) and a runtime (libart.so) that is loaded for starting the Zygote. The dex2oat tool takes an APK file and generates one or more compilation artifact files that the runtime loads. The number of files, their extensions, and names are subject to change across releases, but as of the Android O release, the files being generated are:

1 .vdex: contains the uncompressed DEX code of the APK, with some additional metadata to speed up verification.

2 .odex: contains AOT compiled code for methods in the APK.
3 .art (optional): contains ART internal representations of some strings and classes listed in the APK, used to speed application startup.

)

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