skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  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:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search