Using JDK that is bundled inside Android Studio as JAVA_HOME on Mac

Solution 1:

Add the correct string to .bash_profile (and reload with source .bash_profile):

  1. MacOS versions before Big Sur: export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/.
  2. Catalina, Big Sur, Mentere and above: export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/Contents/Home

If you're using Catalina and above, you most probably use zsh as a shell instead of bash. In that case, add it to .zshrc or .zprofile instead of .bash_profile in your home directory.

Don't forget to restart the operating system after.

After that, running java -version gave this output and Java started to execute normally:

openjdk version "1.8.0_112-release"
OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
OpenJDK 64-Bit Server VM (build 25.112-b06, mixed mode)

As for the Android Device Monitor — it still demands this ancient JRE version 6.

Solution 2:

I just did a fresh install of Android Studio Arctic Fox 2020.3.1 on Big Sur, and I had to use the following.

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

On a slightly different topic, even with the correct JAVA_HOME, ~/Library/Android/sdk/tools/bin/sdkmanager wouldn't start. I had to install "Android SDK Command-line Tools (latest)" (from Android Studio) and use ~/Library/Android/sdk/cmdline-tools/latest/bin/sdkmanager instead.