[error] The operation couldn’t be completed. Unable to locate a Java Runtime


I’ve done the steps as suggested in this post:

But I still get this error whenever I want to build an Android APK file from VS Code running on MacOS Ventura:

✖ Running Gradle build - failed!
[error] The operation couldn’t be completed. Unable to locate a Java Runtime.
        Please visit http://www.java.com for information on installing Java.

Can anyone help me to what I do from here?

Greately appreciated!


If you are using Android Studio bundled jdk, they changed the path to /Applications/Android Studio.app/Contents/jbr/Contents/Home a few versions ago (they replaced jre with jbr in the path)

1 Like


Yes I noticed that when I check the path in Android Studio.

I’ve rund this command in terminal: nano ~/.zshrc
The file was empty, so I added JAVA_HOME=“Applications/Android Studio.app/Contents/jbr/Contents/Home”
I’ve also tried JAVA_HOME=Applications/Android \Studio.app/Contents/jbr/Contents/Home
without the quotations marks.
But it doesn’t seem to work. I still get the same error.
I’m a bit at a loss here.

I have it in .zprofile file, not sure if that makes a difference.

And looks like this, without quotes
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home
Note that the \ goes at the end of Android, not at the beginning of Studio.

Note that you have to open a new terminal so it detects the new JAVA_HOME variable, or run source ~/.zshrc after doing the changes