1

How do i solve this ? I've downloaded Android Studio Preview on my M1 Mac as suggested

error after running flutter doctor

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
[✓] Flutter (Channel beta, 2.3.0-24.1.pre, on macOS 11.4 20F71 darwin-arm,
    locale fr-FR)
[✗] Android toolchain - develop for Android devices
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[!] Android Studio
    ✗ Unable to find bundled Java version.
[✓] VS Code (version 1.58.2)
[✓] Connected device (2 available)

why is it still not working ?

Aristidios
  • 1,921
  • 2
  • 13
  • 24

2 Answers2

3

I've been using SDK Man for years to install, update and change java versions with simple commands. It will take care of the installation and environment variable setup as well.

Here is a simple guide for mac users

Once the sdkman is installed, you can use it from the commandline:

sdk ls java

It will return a table with all the available versions. The cleanest choice is the lastest 'official' LTS version, where the vendor is Java.net and the current latest version is 11.0.11-open

Sdkman also helps you with a command sample at the bottom of the table, so for the current latest LTS openJDK, I would go with:

sdk install java 11.0.11-open

And that's all. Or if you have previously installed java versions (installed through other means) it is best to remove them.

Péter Veres
  • 955
  • 1
  • 10
  • 25
  • is it like homebrew ? will it install the best Java version for my M1 mac? – Aristidios Jul 18 '21 at 22:00
  • yes very similar, but it lets you choose the version you like – Péter Veres Jul 18 '21 at 22:27
  • Removing the older install should mean no problem, as SDKMan does not install java to the conventional location but it installs it under it's own path to make it easier for you to swap versions later and only makes Java available to the rest of the system via setting environment variables. It also makes it easier to have multiple java versions and just swap between them as you like. Here is the official guide to remove the previous install: https://www.java.com/en/download/help/mac_uninstall_java.html – Péter Veres Jul 19 '21 at 12:07
  • Also make sure that once only the SDKMan installation is on your machine, you install, delete and swap between versions only via SDKMan commands to avoid mixups. Here is a cheat sheet: https://sdkman.io/usage – Péter Veres Jul 19 '21 at 12:10
  • I've noticed that the answer has been 'unaccepted' yesterday. So it made me curious, did something go wrong since? – Péter Veres Aug 18 '21 at 09:23
2

Make sure you have a JDK installed (you can get it here) and your $PATH and $JAVA_HOME are set up correctly. These sources can really help:

In case you've already set them up, double check what's going on with your JAVA_HOME by pasting this in terminal:

echo $JAVA_HOME

It should output a path like this (the jdk version may vary):

/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home

If it the path looks the same (or same with different java version), and you have also checked "where java", "java -version" etc, to make sure that the terminal recognises your java well and there is no other obvious java issue, that means that the only thing left is to run these commands one by one:

cd /Applications/Android\ Studio.app/Contents/jre

ln -s ../jre jdk

ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk

Now if you run "flutter doctor -v", you should see no java errors and something like this instead of the previous error:

• Java binary at: /Applications/AndroidStudio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

Hope this helps! It solved the issue for me :)

These answers might help too:

Yulia Ilina
  • 21
  • 1
  • 3
  • thks this worked for me ! I suggest writing the all solution rather than giving links for your answer to be perfect – Aristidios Sep 04 '21 at 07:27
  • @Aristidios thank you for your kind feedback! thought that the links can help to get a deeper understanding of all the processes, which might be useful in the future :) – Yulia Ilina Jan 25 '22 at 12:14