I’ve done the steps as suggested in this post:
The ‘run android’ command kept failing on my Mac (running Big Sur) with the following error:
Running Gradle build - failed!
[capacitor] [error] The operation couldn’t be completed. Unable to locate a Java Runtime.
I struggled for a while with it so just wanted to share what fixed it for me:
Find the SDK path in Android Studio (Android Studio > Preferences… > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK)
Set JAVA_HOME to that path in your .zshrc or .bashrc file. For examp…
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?
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)
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