138

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?

jdek
  • 891
  • 7
  • 20
humazed
  • 74,687
  • 32
  • 99
  • 138

1 Answers1

323

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
  }
} 
frogatto
  • 28,539
  • 11
  • 83
  • 129
  • 5
    After adding the following line I get Error:A problem occurred configuring project ':app'. – Aditya Kamath May 03 '16 at 13:27
  • @AdityaKamath post your problem in new question so I can help you. –  May 03 '16 at 13:29
  • 8
    Adding retroLambda solved that problem for me. https://github.com/evant/gradle-retrolambda – DoronK May 14 '16 at 12:18
  • 2
    Does this work with annotation processing, or would it break compilation? – IgorGanapolsky Jun 17 '16 at 21:28
  • 6
    Luckily we won't need this in a few weeks. Android will have full support for Java 8 language features. Jack will be deprecated. More details here: https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html – YYamil Mar 15 '17 at 17:44
  • **Jack** is no longer required. See this: https://developer.android.com/studio/preview/features/java8-support.html – IgorGanapolsky Apr 17 '17 at 16:08
  • @IgorGanapolsky Were you able to remove jackOptions and still get Java 8 to work? – airowe Aug 28 '17 at 19:14
  • @airowe At this point, Java 8 works without Jack. – IgorGanapolsky Aug 28 '17 at 19:29
  • @IgorGanapolsky If I remove the jackOptions block from my Gradle, it still throws an error. Are you using retroLambda? – airowe Aug 28 '17 at 19:45
  • @airowe Not using any of the legacy plugins. Read: https://developer.android.com/studio/write/java8-support.html – IgorGanapolsky Aug 28 '17 at 20:16
  • To avoid Jack just update your Gradle to 3.0.0-beta1 . Built-in support for Java 8 libraries and certain Java 8 language features. Jack is no longer required, and you should first disable Jack to use the improved Java 8 support built into the default toolchain. . check this one https://developer.android.com/studio/build/gradle-plugin-3-0-0.html – Jahangir Kabir Aug 31 '17 at 19:20
  • Did anyone got this error :transformClassesWithPreJackPackagedLibrariesForDebug after adding jack ? – Biswas Khayargoli Feb 22 '19 at 07:54
  • @BiswasKhayargoli Yes i got that issue "transformClassesWithPreJackPackagedLibrariesForDebug". Any fixes for it? – Maheshvirus Jun 29 '19 at 08:36