How to enable Jack (Java Android Compiler Kit) in android studio
Asked Answered
V

6

68

I am updated my androidstudio 2.1 stable.As per Android Studio 2.1 supports Android N Developer Preview Android studio 2.1 support Jack (Java Android Compiler Kit) compiler .

How to add or use Jack in android studio?

NOTE:

The Jack toolchain is deprecated, as per Java 8 Language Feature Support on Android. However, you may continue to use it to enable Java 8 language features until the replacement is available.

As of this March 14, 2017 announcement, the Jack toolchain is deprecated. Jack was the default Android build toolchain for Android 6.0–8.1.

https://source.android.com/source/jack

Vocalise answered 27/4, 2016 at 4:7 Comment(0)
J
137

The details on what is required to use Jack and how can be found in the documentation.

Here is the relevant part from the docs that goes in build.gradle on how to use jackOptions and set the compileOptions for java 1.8.

android {
    ...
    defaultConfig {
        ...
        jackOptions {
            enabled true
        }
    }

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

UPDATE

The Jack toolchain is now considered deprecated according to this post and work is being done to natively support Java 8 features as part of the Android build system in the coming weeks according to the post.

The post also mentions that there should be little to no work migrating from Jack to the new method in case you still wanted to try enabling Java 8 features with Jack.

UPDATE 2 Preview Built-in Support

You can now try out the new built-in support for Java 8 using the latest Android Studio preview 2.4 preview 6.

For more information on how to enable it or migrate from Jack or Retrolambda see the documentation.

Jespersen answered 27/4, 2016 at 4:47 Comment(6)
I still get an error: Could not find property 'options' on task ':app:compileDebugJavaWithJack'.Dactylic
@Dactylic I found some references that link that error to annotation processors. Are you by any chance using any libraries that do annotation processing such as dagger or butterknife? Looks like Jack only recently got the ability to apply annotation processors on the classpath with Android Gradle Plugin version 2.2.0-alpha1 or higher. If using a lower version you might be able to specify the annotation processor yourself as shown here.Jespersen
@GeorgeMulligan Indeed using annotation processors, but with gradle plugin 2.1.0.Dactylic
@Dactylic Does it work then if you add the annotationProcessor to the dependencies as shown in the site I linked to at the end of the previous comment?Jespersen
@GeorgeMulligan No it does not. Not even close. Getting dozens of Jack errors. This Jack tool is very stupid and should burn in hell.Dactylic
It works for me. By adding jackOptions, it builds. ThanksCuccuckold
S
12

You can enable jack compiler by adding following line in build.gradle file.

android{

compileSdkVersion 23

buildToolsVersion "24rc2"

defaultConfig {
    ...
    jackOptions {
        enabled true
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}}
Slub answered 28/4, 2016 at 0:46 Comment(0)
Z
6

Jack/Jill will be abandoned in the near future, see the Google post. https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html

Zubkoff answered 16/3, 2017 at 9:40 Comment(0)
R
2

1- build.gradle (Module)

defaultConfig {
        //remove jackOptions 
        jackOptions {
            enabled true
        }
    }

2- if you using a third-party that uses Java 8 build.gradle (Project)

buildscript {
    dependencies {
        //remove this line of your third-party dependency
        classpath 'PATH<VERSION>'
    }
}

3-remove retrolamda,apply plugin '....labmda' remove these lines from your module gradle

4- add to build.gradle (Module)

android {

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
Rozellarozelle answered 22/10, 2018 at 20:48 Comment(0)
C
0

insert in block android{}

jackOptions {
            enabled true
        }

it solution

Crenel answered 12/5, 2017 at 12:2 Comment(1)
Thanks for your answer. But Now Jack toolchain is deprecated. Check source.android.com/source/jackVocalise
R
0

Java 8 is supported on Android Studio 3 versions, all this jackOptions is not required longer.

Jack is no longer supported, and you should first disable Jack to use the improved Java 8 support built into the default toolchain.

For more detail read this link:

https://developer.android.com/studio/write/java8-support.html

Rush answered 26/7, 2017 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.