Java Runtime not found

Hi there,

I run Flutter in VS Code, and have been having no issues until today. All of a sudden I cannot build to Android. I've been building to 3 different Android devices (1 emulator; 2 devices (one USB; one wireless)) since I got my MBP (came with Big Sur) a couple months ago. Today it can't find Java.

Research says to check the Java icon in the System Preferences. But there is no Java icon in my System Preferences.

The error is:

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

I also tried a different project via Android Studio, and it says the same thing. But I've BEEN building to Android, so I'm completely confused why today it all of a sudden can't find Java.

When I type which java or which javac they both point to /usr/bin/java and /usr/bin/javac. But typing java -version or /usr/bin/java -version gives that same error.

I went to Oracle, but they mention about costs. And this again makes me wonder... why am I even here?? Where did my Java go?

I also don't surf the web or download/install stuff on my Mac. I only do Flutter development on the Mac.

So do I just not think about how it disappeared, and go ahead and just install the JRE or JDK from Oracle? Or is there a way to tell the Mac to "please fix this"?

Thanks for any insights. -Keith

Accepted Reply

I went ahead and downloaded Java from: https://www.java.com/en/download/

(There was another download page, but it required an Oracle login.)

After installing, I then got the error (when building):

Could not find tools.jar.
Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.

Research Reference:

https://stackoverflow.com/questions/64968851/could-not-find-tools-jar-please-check-that-library-internet-plug-ins-javaapple

The top two suggestions at this SO didn't help (and when using the path mentioned farther below, the emulator wouldn't start and gave a Mac alert error). They both suggested the following:

> /usr/libexec/java_home -V | grep jdk

    Matching Java Virtual Machines (1):
        1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

> vim .zshrc

add the following:

    export JAVA_HOME=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    export PATH=$JAVA_HOME/bin:$PATH

This seems to work for most others. But a 1-vote answer (now 2) had a solution that worked for my situation. There were a few other answers that referenced this fix, but this answer was the clearest.

Go to your project, open android folder > gradle.properties file > add the below line

    org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

Caveat:

Double checking this solution, I opened Applications, right-clicked on Android Studio.app, selected Show Package Contents, then navigated to /Contents/jre, but there was no jdk.

So I just removed the /jdk from the path.

    [/Users/[username]/Documents/src/projects/[projectname]/android/gradle.properties]
    org.gradle.jvmargs=-Xmx1536M
    android.enableR8=true
    android.useAndroidX=true
    android.enableJetifier=true
    org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home
    # org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

Although likely something I did, still no clue what might've changed from last week, and I'll just need to check/add this for each project.

- Keith

Replies

I went ahead and downloaded Java from: https://www.java.com/en/download/

(There was another download page, but it required an Oracle login.)

After installing, I then got the error (when building):

Could not find tools.jar.
Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.

Research Reference:

https://stackoverflow.com/questions/64968851/could-not-find-tools-jar-please-check-that-library-internet-plug-ins-javaapple

The top two suggestions at this SO didn't help (and when using the path mentioned farther below, the emulator wouldn't start and gave a Mac alert error). They both suggested the following:

> /usr/libexec/java_home -V | grep jdk

    Matching Java Virtual Machines (1):
        1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

> vim .zshrc

add the following:

    export JAVA_HOME=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    export PATH=$JAVA_HOME/bin:$PATH

This seems to work for most others. But a 1-vote answer (now 2) had a solution that worked for my situation. There were a few other answers that referenced this fix, but this answer was the clearest.

Go to your project, open android folder > gradle.properties file > add the below line

    org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

Caveat:

Double checking this solution, I opened Applications, right-clicked on Android Studio.app, selected Show Package Contents, then navigated to /Contents/jre, but there was no jdk.

So I just removed the /jdk from the path.

    [/Users/[username]/Documents/src/projects/[projectname]/android/gradle.properties]
    org.gradle.jvmargs=-Xmx1536M
    android.enableR8=true
    android.useAndroidX=true
    android.enableJetifier=true
    org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home
    # org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

Although likely something I did, still no clue what might've changed from last week, and I'll just need to check/add this for each project.

- Keith

Hi Keith,

I had a similar issue with react native but I think installing Java (JRE) is creating a new problem while partly fixing the original. For whatever reason your computer can't find your installed version of JDK. Either a path issue or another issue with the JDK install. This could potentially be fixed by simply updating your Java path in your terminals profile (.profile, .bash_profile, .zshrc, etc). i.e Make sure JAVA_HOME environment variable is set to the JDK’s folder. - if not reinstall JDK (instructions bellow)

When you install Java (JRE) and try build your app, the build now finds Javas JRE which has everything it is needs to run Java but not build it, this is why the new error is Could not find tools.jar.. The JDK includes the compiler (javac) and tools (like javadoc and jdb) and is what is needed to build your app. You then fixed the second error by forcing gradle (build tool) to look in the correct folder for your JDK.

I would recommend fixing this issue fully by first removing the Java you installed by running the following in your terminal:

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Oracle/Java

And then reinstalling the JDK via brew by running: brew reinstall adoptopenjdk8

I just update my android studio to solve this problem.

I had the same issue with macOS Ventura 13.0.1 - I installed homebrew and brew installed java by following this StackOverFlow: https://stackoverflow.com/questions/65601196/how-to-brew-install-java

I think the main part worked for me is this - "you also need to create a symlink for the system Java wrappers to find this JDK:" sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk
/Library/Java/JavaVirtualMachines/openjdk.jdk

I had a similar issue on macOS Ventura 13.5.1 - I installed the java dependencies through homebrew using temurin (https://formulae.brew.sh/cask/temurin#default), which is the newer and default version of adoptopenjdk (https://formulae.brew.sh/cask/adoptopenjdk).