Error:Jack is required to support java 8 language features

AndroidAndroid StudioAndroid Gradle-PluginJack Compiler

Android Problem Overview


When I tried to update my android project to use Java 8 after getting android studio 2.1 and android N SDK by adding

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

I had this error

> Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.

What should I do?

Android Solutions


Solution 1 - Android

> Error:Jack is required to support java 8 language features. Either > enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.

The error say that you have to enable Jack.

To enable support for Java 8 in your Android project, you need to configure your build.gradle file like that

android {
  ...


  compileSdkVersion 23
  buildToolsVersion "24rc2"
  defaultConfig {
  ...
    jackOptions {
      enabled true
    }
  }
 
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
} 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhumazedView Question on Stackoverflow
Solution 1 - Androiduser5248371View Answer on Stackoverflow