简体   繁体   English

JAVA_HOME 设置为无效目录 Android Studio (Flutter)

[英]JAVA_HOME is set to an invalid directory Android Studio (Flutter)

I am using OSX Yosemite on my old mac.我在我的旧 Mac 上使用 OSX Yosemite。 When I installed emulator and try to create a run a Flutter project, I started getting an error about JDK 17. I deleted JDK 17 and installed JDK and also set my path in bash profile to "Library/Java/JavaVirtualMachines/jdk-1.8.0_321.jdk/Contents/Home".当我安装模拟器并尝试创建运行 Flutter 项目时,我开始收到有关 JDK 17 的错误。我删除了 JDK 17 并安装了 JDK,并将我在 bash 配置文件中的路径设置为“Library/Java/JavaVirtualMachines/jdk-1.8. 0_321.jdk/目录/主页”。 However, my Android studio is still giving this error.但是,我的 Android 工作室仍然报这个错误。

ERROR: JAVA_HOME is set to an invalid directory: /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Exception: Gradle task assembleDebug failed with exit code 1

I spent hours solving this.我花了几个小时解决这个问题。 Please help me.请帮我。 Thank you very much.非常感谢你。

I resolved the issue.我解决了这个问题。 Problem was due to 2 versions of Android Studio installed on same device.问题是由于在同一台设备上安装了 2 个版本的 Android Studio。 One was in applications folder and other was in Downloads folder.一个在应用程序文件夹中,另一个在下载文件夹中。 I was using Android Studio in Downloads folder and it's installation files are referring to old JDK plugin that was set for another Android Studio because both have similar paths.我在下载文件夹中使用 Android Studio,它的安装文件指的是为另一个 Android Studio 设置的旧 JDK 插件,因为它们具有相似的路径。

/Applications/AndroidStudio.app/Contents/plugins/java/lib/jdkAnnotations.jar

After deleting old Android Studio and moving other one into Application folder resolved my issue.删除旧的 Android Studio 并将另一个移至应用程序文件夹后解决了我的问题。 Thanks everybody for helping me out.谢谢大家帮助我。

For Windows , maybe similar for macOS:对于Windows ,对于 macOS 可能类似:

The problem is because of trace of old Android Studio java folder, just delete this folder and it starts working:问题是因为旧的 Android Studio java 文件夹的痕迹,只需删除此文件夹即可开始工作:

C:\Program Files\Android\Android Studio\jre C:\Program Files\Android\Android Studio\jre

The new Android Studio Electric Eel is using jbr, not jre.新的 Android Studio Electric Eel 使用的是 jbr,而不是 jre。

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

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