Daniel Abera
Daniel Abera

Reputation: 21

JAVA_HOME is set to an invalid directory android studio (Flutter)

I was working on flutter project on Macbook pro M1 chip but when I run the project it keeps giving me this error

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

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

But I did put the path and I use homebrew to install JAVA and to make sure that I have valid directory when I run the echo $JAVA_HOME command it gives me

/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home

but when I run the /usr/libexec/java_home command it returns

The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java.

I have tried everything I could get on the internet but still give's me this error on running flutter run:

Launching lib/main.dart on sdk gphone16k arm64 in debug mode...

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

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

Running Gradle task 'assembleDebug'...                              25ms
Error: Gradle task assembleDebug failed with exit code 1

I've spent the whole day trying to solve this issue. I would really appreciate your help. Thank you!

What i tried

But none of it helped.

Upvotes: 2

Views: 142

Answers (0)

Related Questions