Is it possible to use Java 8 for Android development?

后端 未结 26 2029
礼貌的吻别
礼貌的吻别 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 22:58

    Yes, Android Supports Java 8 Now (24.1.17)

    Now it is possible

    But you will need to have your device rom run on java 1.8 and enable "jackOptions" to run it. Jack is the name for the new Android compiler that runs Java 8

    https://developer.android.com/guide/platform/j8-jack.html

    add these lines to build_gradle

        android {
      ...
      defaultConfig {
        ...
        jackOptions {
          enabled true
        }
      }
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
    }
    

    Java 8 seem to be the running java engine of Android studio 2.0, But it still does not accept the syntax of java 8 after I checked, and you cannot chose a compiler from android studio now. However, you can use the scala plugin if you need functional programming mechanism in your android client.

提交回复
热议问题