简体   繁体   English

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

[英]Which JDK version (Language Level) is required for Android Studio?

I am a new comer to the android world and with a .NET background. 我是android世界的新角色,拥有.NET背景。 I am trying to install the Android Studio but I am having a mismatch on Android.com about the JDK version required for developing Android applications. 我正在尝试安装Android Studio,但我在Android.com上与开发Android应用程序所需的JDK版本不匹配。

From the SDK web page it states that JDK 6 is required (under system requirements section). SDK网页上,它指出需要JDK 6 (在系统要求部分下)。 Jim Wilson also insist in his course on Pluralsight (which is quite new, from last May) that using version 7 with the Android SDK will create a lot of headache and makes it clear to only use JDK 6. 吉姆威尔逊也坚持他的Pluralsight课程 (这是从去年五月开始的新课程 ),使用版本7和Android SDK将会产生很多麻烦,并且明确只使用JDK 6。

Although in the Android studio page (Under installing step 2) they explain how to set an environment variable indicating the correct JDK location. 虽然在Android工作室页面 (在安装步骤2下),他们解释了如何设置指示正确JDK位置的环境变量。 In here they use a path of JDK 7 在这里,他们使用JDK 7的路径

Select Start menu > Computer > System Properties > Advanced System Properties . 选择Start menu > Computer > System Properties > Advanced System Properties Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example C:\\Program Files\\Java\\jdk1.7.0_21 . 然后打开Advanced tab > Environment Variables并添加一个指向JDK文件夹的新系统变量JAVA_HOME ,例如C:\\Program Files\\Java\\jdk1.7.0_21

I am pretty sure both the ADT & Eclipse bundle and the Android Studio bundle are using the same SDK but now I am confused about which JDK version I need to install. 我很确定ADT和Eclipse软件包以及Android Studio软件包都使用相同的SDK,但现在我对我需要安装哪个JDK版本感到困惑。 My sole purpose is to avoid problems as much as possible while getting my first steps into the Android development. 我唯一的目的是在迈出Android开发的第一步时尽可能避免出现问题。

Disclaimer: I am not related by any mean to Pluralsight. 免责声明:我对Pluralsight没有任何意义。 I am just a normal user following the courses. 我只是跟随课程的普通用户。

Answer Clarification - Android Studio supports JDK8 回答澄清 - Android Studio支持JDK8

The following is an answer to the question "What version of Java does Android support?" 以下是“Android支持哪个Java版本?”这个问题的答案。 which is different from "What version of Java can I use to run Android Studio?" 这与“我可以用什么版本的Java来运行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. 对于那些希望回答第二个问题的人,您可能会发现使用带有Java 1.7的Android Studio很有帮助。

Also: See http://developer.android.com/sdk/index.html#latest for Android Studio system requirements. 另外:有关Android Studio系统要求,请参阅http://developer.android.com/sdk/index.html#latest JDK8 is actually a requirement for PC and linux (as of 5/14/16). JDK8实际上是PC和Linux的要求 (截至2016年5月14日)。


Java 8 update (3/19/14) Java 8更新(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. 因为我认为这个问题将在昨天发布后很快就会出现:截至目前,Android还没有确定何时支持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/ 以下是关于/ 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 . 如果您真的想要lambda支持,可以查看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增加了Java 7支持

Android now supports Java 7 (minus try-with-resource feature). Android现在支持Java 7(减去try-with-resource功能)。 You can read more about the Java 7 features here: https://stackoverflow.com/a/13550632/413254 . 您可以在此处阅读有关Java 7功能的更多信息: https//stackoverflow.com/a/13550632/413254 If you're using gradle, you can add the following in your build.gradle: 如果您使用的是gradle,则可以在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). 我正在使用Java 7与Android Studio没有任何问题(OS X - 10.8.4)。 You need to make sure you drop the project language level down to 6.0 though. 您需要确保将项目语言级别降低到6.0。 See the screenshot below. 请参见下面的截图。

在此输入图像描述

What tehawtness said below makes sense, too. 下面所说的tehawtness也是有道理的。 If they're suggesting JDK 6, it makes sense to just go with JDK 6. Either way will be fine. 如果他们建议使用JDK 6,那么使用JDK 6是有意义的。无论哪种方式都可以。

在此输入图像描述


Update: See this SO post -- https://stackoverflow.com/a/9567402/413254 更新:请参阅此SO帖子 - https://stackoverflow.com/a/9567402/413254

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. 通常,我会按照文档说的那样去,但如果教师明确表示坚持使用JDK 6,我会使用JDK 6,因为您希望您的开发环境尽可能接近教师。 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. 如果你碰到一个问题并且在脑后想到这可能是因为你在JDK 7上遇到了这个问题,那就太糟糕了。 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. 顺便说一句,我最近没有触及过Android,但我个人从未遇到过JDK 7问题,但请注意,我只是随便编写Android应用程序。

Try not to use JDK versions higher than the ones supported. 尽量不要使用高于支持的JDK版本。 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. 我有一个自己的jar库,我用JDK 8编译,我在我的任务中使用它。 It was giving me some kind of preDexDebug error every time I tried running it. 每次我尝试运行它时,它都会给我一些preDexDebug错误。 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. 我检查了系统要求,将编译器从8改为7,并且工作正常。 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 . Android Studio现在捆绑了OpenJDK 8 Legacy projects can still use JDK7 or JDK8 旧版项目仍然可以使用JDK7JDK8

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM