Android Studio 需要哪个 JDK 版本(语言级别) ?

我是机器人世界的新来者。NET 背景。我正在尝试安装 Android Studio,但是在 Android.com 上,关于开发 Android 应用程序所需的 JDK 版本,我有一个不匹配的地方。

SDK 网页它指出 JDK 6是必需的(在系统需求部分)。吉姆 · 威尔逊还坚持在 他的多重视觉课程中(这是去年5月的一个相当新的版本) ,在 Android SDK 中使用版本7将会带来很多麻烦,并且明确表示只能使用 JDK 6。

虽然在 Android 工作室页面中(在安装步骤2下)他们解释了如何设置一个环境变量来指示正确的 JDK 位置。在这里他们使用 JDK 7的路径

选择 Start menu > Computer > System Properties > Advanced System Properties。然后打开 Advanced tab > Environment Variables并添加一个新的系统变量 JAVA_HOME,它指向您的 JDK 文件夹,例如 C:\Program Files\Java\jdk1.7.0_21

我非常确定 ADT & Eclipse 包和 Android Studio 包都使用相同的 SDK,但是现在我不知道需要安装哪个 JDK 版本。我唯一的目的就是在进入 Android 开发的第一步时尽可能地避免问题。

免责声明: 我与 Pluralsight 没有任何关系,我只是一个普通的课程使用者。

119387 次浏览

Normally, I would go with what the documentation says but if the instructor explicitly said to stick with JDK 6, I'd use JDK 6 because you would want your development environment to be as close as possible to the instructors. It would suck if you ran into an issue and having the thought in the back of your head that maybe it's because you're on JDK 7 that you're having the issue. Btw, I haven't touched Android recently but I personally never ran into issues when I was on JDK 7 but mind you, I only code Android apps casually.

Answer Clarification - Android Studio supports JDK8

The following is an answer to the question "What version of Java does Android support?" which is different from "What version of Java can I use to run Android Studio?" which is I believe what was actually being asked. For those looking to answer the 2nd question, you might find Using Android Studio with Java 1.7 helpful.

Also: See http://developer.android.com/sdk/index.html#latest for Android Studio system requirements. JDK8 is actually a requirement for PC and linux (as of 5/14/16).


Java 8 update (3/19/14)

Because I'd assume this question will start popping up soon with the release yesterday: As of right now, there's no set date for when Android will support Java 8.

Here's a discussion over at /androiddev - http://www.reddit.com/r/androiddev/comments/22mh0r/does_android_have_any_plans_for_java_8/

If you really want lambda support, you can checkout Retrolambda - https://github.com/evant/gradle-retrolambda. I've never used it, but it seems fairly promising.

Another Update: Android added Java 7 support

Android now supports Java 7 (minus try-with-resource feature). You can read more about the Java 7 features here: https://stackoverflow.com/a/13550632/413254. If you're using gradle, you can add the following in your build.gradle:

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

Older response

I'm using Java 7 with Android Studio without any problems (OS X - 10.8.4). You need to make sure you drop the project language level down to 6.0 though. See the screenshot below.

enter image description here

What tehawtness said below makes sense, too. If they're suggesting JDK 6, it makes sense to just go with JDK 6. Either way will be fine.

enter image description here


Update: See this SO post -- https://stackoverflow.com/a/9567402/413254

Try not to use JDK versions higher than the ones supported. I've actually ran into a very ambiguous problem a few months ago.

I had a jar library of my own that I compiled with JDK 8, and I was using it in my assignment. It was giving me some kind of preDexDebug error every time I tried running it. Eventually after hours of trying to decipher the error logs I finally had an idea of what was wrong. I checked the system requirements, changed compilers from 8 to 7, and it worked. Looks like putting my jar into a library cost me a few hours rather than save it...

Android Studio now comes bundled with OpenJDK 8 . Legacy projects can still use JDK7 or JDK8

Reference: https://developer.android.com/studio/releases/index.html