Search code examples
androidflutterandroid-studiointellij-ideajava-17

Flutter - IntelliJ IDEA can't find JAVA_HOME after executing flutter run after upgrading Macos Sequoia


I'm using M3 Pro Sequaoia. I got a flutter project, running flutter run I got this error

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

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

Error: Gradle task assembleDebug failed with exit code 1

Running flutter doctor -v I got

enter image description here

Running:

zhelon@MacBook-Pro-M3-de-Sebastian-2 ~ % echo $JAVA_HOME

(nothing)

Running:

zhelon@MacBook-Pro-M3-de-Sebastian-2 ~ % which java
/usr/bin/java

Running:

zhelon@MacBook-Pro-M3-de-Sebastian-2 ~ % java -version
openjdk version "17.0.12" 2024-07-16
OpenJDK Runtime Environment Homebrew (build 17.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.12+0, mixed mode, sharing)

I just reinstalled intellij IDEA and Android Studio. This is my android sdk: enter image description here

.bash_profile

# export PATH=”/opt/homebrew/opt/openjdk@17/bin:$HOME/.jenv/bin:$PATH:/Users/zhelon/development/flutter/bin”
export PATH=”$PATH:/Users/zhelon/development/flutter/bin”

# export JAVA_HOME=`/usr/libexec/java_home -v 17`
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

can I get some hand please?


Solution

  • Apart of reinstalling, you can try installing jdk21 using brew with brew install openjdk@21 then replace your .bash_profile and .zshenv with

    export PATH=”$PATH:/Users/zhelon/development/flutter/bin:$JAVA_HOME/bin”
    export JAVA_HOME="/opt/homebrew/opt/openjdk@21"
    export LANG=en_US.UTF-8
    export LANGUAGE=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    

    then refresh source ~.bash_profile and source ~.zshenv

    finally try

    flutter config --jdk-dir $JAVA_HOME

    and should work