Android supports all Java 7 language features and a subset of Java 8 language
features that vary by platform version. This page describes the new language
features you can use, how to properly configure your project to use them, and
any known issues you may encounter.

Note: When developing apps for Android, using Java 8
language features is optional. You can keep your project's source and target
compatibility values set to Java 7, but you still need to compile using JDK
8.

This page shows you how to enable support for Java 8 language features using a
compiler called Jack,
which is available only on Android Studio 2.1 and higher.

If you already have Android Studio installed, make sure you update to the
latest version by clicking Help > Check for Update (on
Mac, Android Studio > Check for Updates). If you don't
already have the IDE installed on your workstation, download Android Studio here.

Supported Java 8 Language Features and APIs

Android does not support all Java 8 language features. However, the
following features are available when developing apps targeting
Android 7.0 (API level 24):

Note: Note: Type annotation information is available at compile time, but not
at runtime. Also, the platform supports TYPE
in API 24 and below, but not ElementType.TYPE_USE or
ElementType.TYPE_PARAMETER..

To test lambda expressions, method references, and type annotations on
earlier versions of Android, go to your build.gradle file, and set
compileSdkVersion and targetSdkVersion to 23 or lower. You
will still need to enable the Jack toolchain to
use these Java 8 features.

Enable Java 8 Features and the Jack Toolchain

In order to use Java 8 language features, you need to also use the
Jack toolchain.
This Android toolchain compiles Java language sources into
Android-readable DEX bytecode, has its own .jack library format, and
provides most toolchain features as part of a single tool: repackaging,
shrinking, obfuscation and multidex.

Here is a comparison of the two toolchains used to build Android DEX files:

Legacy javac toolchain:javac (.java → .class) → dx (.class → .dex)

New Jack toolchain:Jack (.java → .jack → .dex)

Configure Gradle

To enable Java 8 language features and Jack for your project, enter the
following in your module-level build.gradle file: