BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Android Studio Switched to New D8 Compiler

Android Studio Switched to New D8 Compiler

This item in japanese

Recently released Android Studio 3.1 switched to a new DEX compiler which promises to provide better and faster compilation, writes Google software engineer Jeffrey van Gogh. Compared to the previous compiler, called DX, D8 compiles faster and outputs smaller DEX files, all while having the same or better app runtime performance.

The conversion of .class bytecode into .dex bytecode for the Android Runtime is an essential step when building an app for Android, and the process directly impacts the overall build time and app performance. Using its own benchmark project, Google has observed both faster compilation times (by a 20% factor) and smaller .dex file sizes (although by just a few percent). However, these results should be taken with a pinch of salt, as they are based on a single benchmark. A few users have actually reported slower compilation times when using D8 from Android Studio 3.0.

Among the other advantages of using D8 is its support for desugaring, which makes it possible to translate into Java 7 features that are only available in Java 8, such as lambdas. Integrating the desugaring step into D8 impacts all developers of tools that read or write .class bytecode, since it will use the Java 8 format. You can revert to the previous behaviour, where desugaring happened just after the Java compilation and .class bytecode followed the Java 7 format, by setting a property in your gradle file:

android.enableD8.desugaring=true

Should you experience any general issue with D8, you can revert to DX changing a setting in your gradle.properties file, as shown below:

android.enableD8=false

The fact that D8 is now the default compiler in Android Studio does not mean developers have to rush to migrate their apps. Indeed, the old DX compiler will remain available until Google has gathered enough confidence that D8 cannot cause any regressions for users. This means Google will continue to fix bugs found in DX for at least six months. During this first phase, Google engineers will carefully monitor the D8 bug tracker to find any issues that could be a showstopper in the migration plan. After six months free of major regressions, Google will keep DX available for at least one year, in order to ensure that any development team gets plenty of time to migrate. After that, DX will only be available through a legacy version of Android Studio.

Rate this Article

Adoption
Style

BT