Is it possible to use Java 8 for Android development?

后端 未结 26 2335
礼貌的吻别
礼貌的吻别 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条回答
  •  失恋的感觉
    2020-11-21 23:04

    I wrote a similar answer to a similar question on Stack Overflow, but here is part of that answer.

    Android Studio 2.1:

    The new version of Android Studio (2.1) has support for Java 8 features. Here is an extract from the Android Developers blogspot post:

    ... Android Studio 2.1 release includes support for the new Jack compiler and support for Java 8.

    ...

    To use Java 8 language features when developing with the N Developer Preview, you need to use the Jack compiler. The New Project Wizard [File→ New→ Project] generates the correct configurations for projects targeting the N.


    Prior to Android Studio 2.1:

    Android does not support Java 1.8 yet (it only supports up to 1.7), so you cannot use Java 8 features like lambdas.

    This answer gives more detail on Android Studio's compatibility; it states:

    If you want to use lambdas, one of the major features of Java 8 in Android, you can use gradle-retrolamba

    If you want to know more about using gradle-retrolambda, this answer gives a lot of detail on doing that.

提交回复
热议问题