Is it possible to use Java 8 for Android development?

后端 未结 26 2024
礼貌的吻别
礼貌的吻别 2020-11-21 22:50

Searching the web, it is not clear if Java 8 is supported for Android development or not.

Before I download/setup Java 8, can some one point me at any \"official\" d

26条回答
  •  梦毁少年i
    2020-11-21 23:03

    Follow this link for new updates. Use Java 8 language features

    Old Answer

    As of Android N preview release Android support limited features of Java 8 see Java 8 Language Features

    To start using these features, you need to download and set up Android Studio 2.1 and the Android N Preview SDK, which includes the required Jack toolchain and updated Android Plugin for Gradle. If you haven't yet installed the Android N Preview SDK, see Set Up to Develop for Android N.

    Supported Java 8 Language Features and APIs

    Android does not currently support all Java 8 language features. However, the following features are now available when developing apps targeting the Android N Preview:

    Default and static interface methods

    Lambda expressions (also available on API level 23 and lower)

    Repeatable annotations

    Method References (also available on API level 23 and lower)

    There are some additional Java 8 features which Android support, you can see complete detail from Java 8 Language Features

    Update

    Note: The Android N bases its implementation of lambda expressions on anonymous classes. This approach allows them to be backwards compatible and executable on earlier versions of Android. To test lambda expressions on earlier versions, remember to go to your build.gradle file, and set compileSdkVersion and targetSdkVersion to 23 or lower.

    Update 2

    Now Android studio 3.0 stable release support Java 8 libraries and Java 8 language features (without the Jack compiler).

提交回复
热议问题