# Android's Java 8 Support

DevFeed: [Android's Java 8 Support](<https://devfeed.tech/articles/android-s-java-8-support-20917.md>)

Original publisher: [Read original article](<https://jakewharton.com/androids-java-8-support/>)

Published: 2018-11-20T00:00:00Z

Content type: article

Language: en

Sources: [Jake Wharton](<https://devfeed.tech/sources/jake-wharton.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Java](<https://devfeed.tech/topics/java.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [java](<https://devfeed.tech/tags/java.md>), [toolchain](<https://devfeed.tech/tags/toolchain.md>)

## AI overview

The article explains Android's Java 8 support, focusing on language features such as lambdas and how Android's toolchain handles their newer bytecode. It describes desugaring, which transforms these features into representations compatible with older API levels, and reviews the evolution from Retrolambda to later compiler-based approaches.

## Source excerpt

I've worked from home for a few years, and during that time I've heard people around the office complaining about Android's varying support for different versions of Java. Every year at Google I/O you could find me asking about it at the fireside chats or directly to the folks responsible. At conferences and other developer events it comes up in conversation or in talks with different degrees of accuracy. It's a complicated topic because what exactly we mean when talking about Android's Java support can be unclear. There's a lot to a single version of Java: the language features, the bytecode, the tools, the APIs, the JVM, and more. When someone talks about Android's Java 8 support they usually are referring to the language features. So let's start there with a look at how Android's toolchain deals with the language features of Java 8. Lambdas The banner language feature of Java 8 was by far the addition of lambdas. This brought a more terse expression of code as data whereas previously more verbose constructs like anonymous classes would be used. class Java8 { interface Logger { void log(String s); } public static void main(String... args) { sayHi(s -> System.out.println(s)); } private static void sayHi(Logger logger) { logger.log("Hello!"); } } After compiling this program with javac, running it through the legacy dx tool produces an error. $ javac *.java $ ls Java8.java Java8.class Java8$Logger.class $ $ANDROID_HOME/build-tools/28.0.2/dx --dex --output . *.class Uncaught translation error: com.android.dx.cf.code.SimException: ERROR in Java8.main:([Ljava/lang/String;)V: invalid opcode ba - invokedynamic requires --min-sdk-version >= 26 (currently 13) 1 error; aborting This is because lambdas use a newer bytecode, invokedynamic, added in Java 7. As the error message indicates, Android's support for this bytecode requires a minimum API of 26 or newer-something practically unfathomable for applications at the time of writing. Instead, a process named desugaring is us