skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.

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

    After deleting old Android Studio and moving other one into Application folder resolved my issue. Thanks everybody for helping me out.


  2. For Windows:

    The problem is because of trace of old Android Studio java folder, just delete this folder and it starts working:

    C:Program FilesAndroidAndroid Studiojre
    

    The new Android Studio Electric Eel is using jbr, not jre.


    For macOS:
    If you are using macOS replace the path in .bash_profile or .zshrc

    export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
    

    with

    export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search