Which Java JDK should I install for the use of Android Studio

眉间皱痕 提交于 2020-08-25 01:40:25

问题


I want to install Android Studio and I saw that it is recommended to also install the Java JDK. The thing that I don't understand is that a lot of people are recommending the Java SE Development Kit 8 but the latest one is 13. Why would I use 8 instead of 13? Can anyone tell me the exact version of JDK that should be used for Android Studio?

Thanks in advance.


回答1:


The official doc says:

Set the JDK version

A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects. To use the bundled JDK, do the following:

  1. Open your project in Android Studio and select File > Project Structure in the menu bar.
  2. In the SDK Location page and under JDK location, check the Use embedded JDK checkbox.
  3. Click OK.

So there is no need to install a standalone JDK if you are not planning to do Java Devs other than Android App.




回答2:


Android is behind the Java development.

It uses most of Java 7's features with some features of Java 8 (like click listeners using lambdas).

To make Android Studio "understand" Java 8, you have to add the following options to your app's build.gradle android section:

 compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

So, if you would like to be able to copy-paste code from your java applications to Android ones, it is better to stick to Java 8.




回答3:


You can use Java 8 or java 7 for the android studio 3 or later versions. I was having some problem with java 13 . After some research i found it , Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features

Hope it helps :)



来源:https://stackoverflow.com/questions/58379215/which-java-jdk-should-i-install-for-the-use-of-android-studio

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