Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set sourceCompatability to javaVersion.VERSION_1_8

I installed jdk1.8.0_112 and write code below in build.gradle

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

i received this error

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

Can anyone help me?

like image 573
Moeen Kashisaz Avatar asked Dec 04 '16 09:12

Moeen Kashisaz


2 Answers

from https://developer.android.com/guide/platform/j8-jack.html, you also need following:

  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }

UPDATE

Note that Jack toolchain is now deprecated https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html

like image 80
John O'Reilly Avatar answered Nov 14 '22 16:11

John O'Reilly


Android Studio 3.0 Preview 1 and later supports all Java 7 language features and a subset of Java 8 language. Jack is no longer supported, and you should first disable Jack to use the improved Java 8 support built into the default toolchain.

From: Use Java 8 language features

like image 2
Kevin Barja Avatar answered Nov 14 '22 17:11

Kevin Barja