Native Java 8 arrives on android! Finally!

Starting with Android Studio 2.4 Preview 4 and android gradle plugin version 2.4.0-alpha4, Java 8 language features are now natively supported by android:

Also from min API level 24 the following Java 8 API are available:

  • java.util.stream
  • java.util.function
  • java.lang.FunctionalInterface
  • java.lang.annotation.Repeatable
  • java.lang.reflect.AnnotatedElement.getAnnotationsByType(Class)
  • java.lang.reflect.Method.isDefault()

The Android team promised that more Java 8 features are going to be added in the future.

How can I enable this then?

Add the following to your project’s main build.gradle:

buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.4.0-alpha7'
}
...
}

Add these lines to your application module’s build.gradle to inform the project of the language level:

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}


You’re done! You can now use native java8!