I am using OSX Yosemite on my old mac. 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". However, my Android studio is still giving this error.
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.
2
Answers
I resolved the issue. Problem was due to 2 versions of Android Studio installed on same device. 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.
After deleting old Android Studio and moving other one into Application folder resolved my issue. Thanks everybody for helping me out.
For Windows:
The problem is because of trace of old Android Studio java folder, just delete this folder and it starts working:
The new Android Studio Electric Eel is using
jbr
, notjre
.For macOS:
If you are using macOS replace the path in .bash_profile or .zshrc
with