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

安稳与你 提交于 2019-11-26 15:25:38

问题


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.

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


回答1:


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.




回答2:


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
}}



回答3:


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




回答4:


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
    }
}



回答5:


insert in block android{}

jackOptions {
            enabled true
        }

it solution




回答6:


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



来源:https://stackoverflow.com/questions/36880115/how-to-enable-jack-java-android-compiler-kit-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!