skip to Main Content

Setting up Flutter on MacOS Ventura 13.2 on an M1 MacBook Air. I’ve installed everything to get [✓] except for flutter doctor unable to find a bundled jre in Android Studio. I have found some other questions on this site, but none helped.

alan@Alans-MacBook-Air ~ % flutter doctor   
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.0, on macOS 13.2 22D49 darwin-arm64 (Rosetta), locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.
[✓] VS Code (version 1.74.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

Here’s the full output of the Android Studio section:

[!] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

I have java installed:

alan@Alans-MacBook-Air ~ % java -version 
java version "19.0.2" 2023-01-17
Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
alan@Alans-MacBook-Air ~ % /usr/libexec/java_home 
/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home

I also have my environment setup correctly, I think:

alan@Alans-MacBook-Air ~ % echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home

Some other questions suggest playing with symlinks in the jre folder in the Android Studio install, but I have no jre folder in there. There is however a jbr folder, which appears to contain an OpenJDK build. But I don’t know how to get flutter to see/use it.

alan@Alans-MacBook-Air ~ % /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
OpenJDK 64-Bit Server VM (build 11.0.15+0-b2043.56-8887301, mixed mode)

Installed all the components as required in the documentation. I think I’ve set environment and other parts up correctly.

2

Answers


  1. UPDATE 2

    While the suggestion in Update 1 would work, this is not a "script" interpreted in real-time, and rather part of the flutter binary (if I am not mistaken), so in order for this to work, one would have to compile the flutter binary again, I don’t know how to do that right now (as I’ve never used flutter beyond the basics) and I can’t certainly do it on my "work machine" where the Corporate eyes forbid everything that is fun.

    In other words, use the symlink trick you found in this GitHub issue until the Flutter team releases an updated flutter that searches for the correct java Path in the newer versions of Android Studio.

    And Jetbrains, please, stop renaming the java location every other year…

    UPDATE 1

    In the flutter sdk, there’s a file called: android_studio.dart. (well there are various android related files, none "java" related, since it seems like Flutter treats Java as an "android thing" (judging by the fact that all java references and validations or checks are performed in android_ files).

    This file is located in path/to/flutter/packages/flutter_tools/lib/src/android/android_studio.dart.

    Inside it contains this to calculate the path to java:

        final String javaPath = globals.platform.isMacOS ?
            version != null && version.major < 2020 ?
            globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') :
            globals.fs.path.join(directory, 'jre', 'Contents', 'Home') :
            globals.fs.path.join(directory, 'jre');
    

    In essence, if you add another entry like this:

            globals.fs.path.join(directory, 'jbr', 'Contents', 'Home') :
    

    So it ends up looking like:

        final String javaPath = globals.platform.isMacOS ?
            version != null && version.major < 2020 ?
            globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') :
            globals.fs.path.join(directory, 'jre', 'Contents', 'Home') :
            globals.fs.path.join(directory, 'jbr', 'Contents', 'Home') :
            globals.fs.path.join(directory, 'jre');
    

    Then you can run flutter doctor and it may work.

    I also removed the && version.major < 2020 part, just to ensure it was always run. Now I see:

    [!] Android Studio (version 2022.1)
        ✗ Unable to find bundled Java version.
    [✓] Android Studio (version 2021.3)
    

    So… Two different Android Studio versions, the latest (the one with jbr instead of jre seems to work fine.


    In Android Studio Electric Eel, the bundled Java was moved to /Applications/Android Studio.app/Contents/jbr/Contents/Home so you can set your $JAVA_HOME to point to that directly.

    In Addition, if you’re on macOS (as it looks like that’s the case) remember macOS uses (for some Apple reason) a binary called java_home to set the JAVA installations.

    You can find this binary in /usr/libexec/java_home.

    It seems like the flutter plug-in may be looking for Java under the assumption that it’s under the "old" jre instead of the "new" jbr folder. I don’t know if this is hardcoded (and therefore needs a ‘patch’) or if it just reads the environment variable for JAVA_HOME.

    Login or Signup to reply.
  2. Are you using Jetbrain Toolbox to manage Android Studio?

    If so, my solution may work for you.
    I’m also using M1Air, Flutter 3.7.0, Android Studio Electric Eel 2022.1.1

    cd ~/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/{ YOUR_VERSION_OF_ANDROID_STUDIO }/Android Studio.app/Contents/

    run ls and look for /jbr

    run sudo ln -s jbr jre and flutter doctor

    This solved my problem.

    EDIT

    Your version of Android Studio can be found at Jetbrain Toolbox -> Android Studio -> Settings(3 dots on the right) -> Configuration -> Install Location

    Related Github Issue

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