Android Studio - 提供的 javaHome 不是有效文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22749200/
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-08-13 17:40:33  来源:igfitidea点击:

Android Studio - supplied javaHome is not a valid folder

javaandroid-studiojava-8

提问by Ellis

I decided to update my JDK to Java 8, and installed to the default location of C:\Program Files\Java\jdk1.8.0with a jresubdirectory.

我决定将我的 JDK 更新为 Java 8,并安装到C:\Program Files\Java\jdk1.8.0带有jre子目录的默认位置。

I wasn't sure how Android Studio worked out the JDK location, so I decided to launch it and see. I got the following message:

我不确定 Android Studio 是如何计算出 JDK 位置的,所以我决定启动它看看。我收到以下消息:

Failed to complete Gradle execution.

Cause: Supplied javaHome is not a valid folder. You supplied: C:\Program Files\Java\jdk1.7.0_45

无法完成 Gradle 执行。

原因:提供的 javaHome 不是有效文件夹。您提供了:C:\Program Files\Java\jdk1.7.0_45

I updated my JAVA_HOME environment variable (both for system and user) to point to the new path, and tried adding it to my PATH variable as well, but every time I attempt to build in Android Studio I get the same message. The quoted path is nowhere to be found in my environment variables though, so where is it getting it from and how can I change it?

我更新了我的 JAVA_HOME 环境变量(系统和用户)以指向新路径,并尝试将其添加到我的 PATH 变量中,但每次我尝试在 Android Studio 中构建时,我都会收到相同的消息。但是,在我的环境变量中找不到引用的路径,那么它从哪里获取以及如何更改它?

Thanks

谢谢

采纳答案by Ellis

The problem was my project'sJDK location. From the Android Studio Project tool window, I right clicked on the root directory, selected 'module settings', and set the JDK location. Everything's fine now.

问题是我的项目的JDK 位置。在 Android Studio 项目工具窗口中,我右键单击根目录,选择“模块设置”,然后设置 JDK 位置。现在一切都很好。

回答by Al Lelopath

For Android Studio 1.1.0, after right-clicking on the project:
Select Open Module Settings
Select SDK Locationat top left
Type text into JDK Location:box

对于 Android Studio 1.1.0,右键单击项目后:
选择左上角的Open Module Settings
选择 Type text into boxSDK Location
JDK Location:

回答by omJohn8372

I'm in 1.0.2 and after I clicked OK, it immediately opened a dialog to allow me to specify the location for my project, no longer requiring navigation of the menus to edit the project JDK path.

我在 1.0.2 中,单击“确定”后,它立即打开一个对话框,允许我指定项目的位置,不再需要导航菜单来编辑项目 JDK 路径。

Definitely strange that during install, it says the JAVA_HOME environment variable is set to a path that doesn't contain the JDK. After spending time fixing it (downloading the full 64 bit JDK), I create my first project and get the same thing. Because it's not using the environment variable that it hinges on during setup.

绝对奇怪的是,在安装过程中,它说 JAVA_HOME 环境变量设置为不包含 JDK 的路径。在花时间修复它(下载完整的 64 位 JDK)后,我创建了我的第一个项目并得到了同样的结果。因为它没有使用它在安装过程中依赖的环境变量。

Odd behavior.

奇怪的行为。

回答by nikc

I was also seeing this same problem. For me the fix was in 'Run/Debug Configurations' (Run > Edit Configurations...)

我也看到了同样的问题。对我来说,修复是在“运行/调试配置”中(运行 > 编辑配置...)

The 'Gradle project' value was set to the build.gradle file location, and this should've been set to the Gradle project object in IDEA, click the folder looking icon not the '...'.

'Gradle project' 值设置为 build.gradle 文件位置,这应该已经设置为 IDEA 中的 Gradle 项目对象,单击文件夹查看图标而不是 '...'。

回答by Desik

Try to delete all .iml files and .idea, and re-import the project from Gradle. Worked for me (provided you have everything else set up).

尝试删除所有 .iml 文件和 .idea,然后从 Gradle 重新导入项目。为我工作(前提是你已经设置了其他一切)。

This error happens when you switch from Intellij to Android Studio, or the other way around, and load the same project. Looks like their project model is not compatible.

当您从 Intellij 切换到 Android Studio 或其他方式并加载相同的项目时,会发生此错误。看起来他们的项目模型不兼容。

回答by stuf99

I ran into the same issue. My jdk was upgraded from a 1.8.0_172 to 1.8.0_202. And I kept getting the mentioned error although I changed to the right jdk, in the module configurations. What confused me was the fact that the API version was stamped with the old *_172 version in the dropdown of available project sdk's. I found the reason for this to be an old obsolete entry in the dropdown that referenced the old *172. After deleting this entry, the APi versions was magically stamped with the new version.

我遇到了同样的问题。我的 jdk 从 1.8.0_172 升级到 1.8.0_202。尽管我在模块配置中更改了正确的 jdk,但我一直收到提到的错误。让我感到困惑的是,API 版本在可用项目 sdk 的下拉列表中标有旧的 *_172 版本。我发现其原因是引用旧 *172 的下拉列表中的旧过时条目。删除此条目后,API 版本被神奇地标记为新版本。

Java versions

Java版本

Note to self: Remember to sanitize your projects when new versions come along

自我注意:记住在新版本出现时清理您的项目