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 ?
2
Answers
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:
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 is11.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:
And that’s all. Or if you have previously installed java versions (installed through other means) it is best to remove them.
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:
It should output a path like this (the jdk version may vary):
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:
Now if you run "flutter doctor -v", you should see no java errors and something like this instead of the previous error:
Hope this helps! It solved the issue for me 🙂
These answers might help too: