java 安卓工作室 2.2。预览 1 错误:“请使用 JDK 8 或更新版本”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37335214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:24:34  来源:igfitidea点击:

Android Studio 2.2. Preview 1 error: "Please use JDK 8 or newer"

javaandroidandroid-studioandroid-studio-2.2

提问by der_Fidelis

On trying to run Android Studio 2.2 Preview 1, it gives the following error on gradle build:

在尝试运行 Android Studio 2.2 Preview 1 时,它在构建 gradle 时出现以下错误:

Error:Please use JDK 8 or newer.

错误:请使用 JDK 8 或更新版本。

If I try and do it from the console it says:

如果我尝试从控制台执行此操作,它会说:

FAILURE: Build failed with an exception.

  • Where: Build file 'C:\Coding\Android projects\MaterialScrollBar\app\build.gradle' line: 1

  • What went wrong: A problem occurred evaluating project ':app'. com/android/Hyman/api/ConfigNotSupportedException : Unsupported major.minor version 52.0

FAILURE:构建失败,出现异常。

  • 其中:构建文件“C:\Coding\Android projects\MaterialScrollBar\app\build.gradle”行:1

  • 出了什么问题:评估项目“:app”时出现问题。com/android/Hyman/api/ConfigNotSupportedException:不支持的major.minor版本52.0

I've tried to change the JDK as it suggests from jdk 1.7 to 1.8, but each time I change the JDK location for the project to any other path than the one it currently has it resets back immediately. Even if I change it to other versions of 1.7 it won't change.

我尝试将 JDK 从 jdk 1.7 更改为 1.8,但是每次我将项目的 JDK 位置更改为当前拥有的路径以外的任何其他路径时,它都会立即重置。即使我将其更改为 1.7 的其他版本,它也不会更改。

I've verified that the environmental variables all point to 1.8 and still no dice. AS 2.1 recognises the JDK as 1.8 for the same project.

我已经验证环境变量都指向 1.8 并且仍然没有骰子。对于同一项目,AS 2.1 将 JDK 识别为 1.8。

采纳答案by George Mulligan

I ran into this issue with a previous version of Android Studio. When I first installed Android Studio I was able to reference JDK 7 in my Program Files directory.

我在使用以前版本的 Android Studio 时遇到了这个问题。当我第一次安装 Android Studio 时,我能够在我的 Program Files 目录中引用 JDK 7。

When I upgraded Android Studio and tried to update it to point to JDK 8, which was also in my Program Files directory, I got the same behavior you are seeing. The new path never took and it still used JDK 7.

当我升级 Android Studio 并尝试将其更新为指向 JDK 8(也在我的 Program Files 目录中)时,我得到了与您所看到的相同的行为。新路径从未采用,它仍然使用 JDK 7。

Turns out Android Studio does not like spaces in the paths to the Android SDK and the JDK. Installing the JDK in a location that does not contain any spaces allowed me to update the location through the Project Structure window.

事实证明,Android Studio 不喜欢 Android SDK 和 JDK 路径中的空格。在不包含任何空格的位置安装 JDK 允许我通过“项目结构”窗口更新该位置。

回答by Episodex

If you use Android Studio 2.2 Preview 2 and have same error just check "Use embedded JDK" in SDK Location. Use embedded JDK

如果您使用 Android Studio 2.2 Preview 2 并且遇到相同的错误,只需在 SDK Location 中检查“使用嵌入式 JDK”。 使用嵌入式 JDK

回答by Cory Roy

Make sure you set it in the project structure

确保在项目结构中设置它

Use File -> Project Structure to set the SDK and JDK. I think you are modifying a generated file.

使用 File -> Project Structure 设置 SDK 和 JDK。我认为您正在修改生成的文件。

Also try adding this in your gradle file:

也尝试在你的 gradle 文件中添加这个:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

回答by Tamil Selvan S

if you are using 3.0.1 first enable the use embedded jdk option from File-> project structure -> enable use embedded jdk

如果您使用的是 3.0.1,首先从文件-> 项目结构-> 启用使用嵌入式 jdk 选项启用使用嵌入式 jdk

回答by SWIZYBREAKZ

This worked out perfectly when I had an issue with gradle:

当我遇到 gradle 问题时,这很有效:

  1. First verify that your JDKis indeed higher than JDK 8jdk version .
  2. Press Ctrl+Alt+Shift+Sto open project structure .
  3. Then I selected Use the embedded JDK.
  4. Click OKand retry it.
  1. 首先验证您JDK的确实高于JDK 8jdk 版本。
  2. Ctrl+Alt+Shift+S打开项目结构。
  3. 然后我选择了Use the embedded JDK.
  4. 单击OK并重试。

回答by Hiren

Yes, I strongly agree with Episodex. but still, the problem would occur please do as described below, Click on File menu at the top of the left corner and a select menu of Invalidate caches/Restart... enter image description here

是的,我非常同意 Episodex。但仍然会出现问题,请按如下所述操作,单击左上角的文件菜单和无效缓存/重新启动的选择菜单... 在此处输入图片说明