Skip to content

Android's Java 8 Support

Guillaume Husta edited this page Nov 21, 2018 · 10 revisions

Overview

The new dex compiler is now D8 and was introduced in Android Studio 3.0. It was made the default dexer in Android Gradle plugin 3.1 and it then became responsible for desugaring in 3.2.
See this article from 2017, and an example of generated bytecode (2018).

Sometimes, desugaring won’t help, and some parts of the Java 8 API need a minimum version of the Android API.
You can have a more precise idea of which new APIs was added in Java 8 by looking at Desugaring APIs.

For example, when using

list.sort( Comparator.comparing( <lambda or method reference> ) );

we will need API 24 (see reference doc).

Another example, the usage of Date / Time API is possible starting from API 26 (Oreo 8.0).

Desugaring

As explained in this article, desugaring will transform Java 8 class files to Java 7-compatible class files.
So you can use lambdas, method references and other features of Java 8.

References :

Clone this wiki locally