83

I'm facing a weird issue. Before I updated my Android Studio, everything went fine in flutter doctor. Once I've updated Android Studio, when I run the doctor, it's showing "Unable to find bundled Java version". I've already downloaded Java installer and installed it on my M1 Mac, but after I restarted, running flutter doctor still shows the same error. The weird thing is, when I uninstall the Arctic Fox version and re-install the older Android Studio version, everything goes fine again when running the doctor. How can I resolve this?

Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
Mohamad Faris
  • 933
  • 1
  • 6
  • 5
  • Which `$JAVA_HOME` directory is used? You might wanna check your Java version is compatible with stable AS 2020.3.1 and M1 as well – mochadwi Jul 29 '21 at 03:11
  • here is the answer for this problem when you still wanna using Android Studio Arctic Fox version https://stackoverflow.com/a/68575967/9101876 – Alexa289 Jul 31 '21 at 02:25
  • Does this answer your question? [Unable to find bundled Java version on Flutter](https://stackoverflow.com/questions/51281702/unable-to-find-bundled-java-version-on-flutter) – eja Jan 19 '23 at 05:44

16 Answers16

192

The answer is already posted here.

For Mac User:

Set Java_Home path using below article & then after applying this command.

after that type below command in terminal:

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

ln -s ../jre jdk

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

flutter doctor -v
Ole Pannier
  • 3,208
  • 9
  • 22
  • 33
Taady
  • 2,409
  • 2
  • 10
  • 24
  • 4
    it seems now flutter requires java 11 rather than java 8 since new android studio artic fox update – Kedar Sukerkar Aug 14 '21 at 20:13
  • I just went through the process with the latest flutter and the latest android studio. The solution presented here eliminates the "unable to find java version" error but then you get a ClassNotFoundException on some XML parser classes when trying to accept licenses. That's because Android Studio now comes with Java 1 which does not have a lot of the JEE stuff anymore. The simple solution to all this is to set your JAVA_HOME env variable to any Java 8 install you may have around, and this fixes everything. – entzik Aug 18 '21 at 09:04
  • Working on Mac OS – Bholendra Singh Aug 20 '21 at 11:32
  • works for me without harming pre installed java version 11.0 – Hansa Tharuka Aug 22 '21 at 02:47
  • This worked for me - note I had to manually install the latest JDK first (I am using MacOS big sur) apparently it does not come installer. After that this worked perfectly. – deadant88 Sep 05 '21 at 07:22
  • Worked for me with Big Sur. But would be nice to explain what this `ln -s` command is doing? – Raphael Pinel Sep 08 '21 at 10:42
  • https://github.com/flutter/flutter/issues/118502 – rafahead Feb 11 '23 at 11:56
78

If you are using Android Studio Electric Eel | 2022.1.1.

On Mac

  1. Open "Applications" in Finder. Then right click on Android Studio, select "Show Package Contents".
  2. Inside it, open the "Contents" folder. Inside it you will see folder with named "jbr".
  3. Simply duplicate the "jbr" folder. Then, rename the copy folder to "jre".
  4. Then, flutter doctor. The "Unable to find bundled Java version" warning will disappear.

Thanks to @Javi for provided with alternative method. For Step 2 & 3, ln -s jbr jre also can get the job done. And I think this is the best method to do.

khairudin
  • 820
  • 6
  • 8
  • 5
    You my friend are a genius, I can confirm this was the fix for me as well on Windows 11 using Android studio 2022.1.1 thank you very much sir! – demo7up Jan 14 '23 at 09:44
  • 1
    Hey, how did you come up with this solution? Anyway, it worked for me too. – Su Mit Jan 16 '23 at 11:11
  • 2
    This is the only working solution for me. – Hammas Ali Jan 17 '23 at 04:50
  • wow! after 2 hours trying, this helps me! thanks – Felipe Sales Jan 20 '23 at 22:28
  • 5
    Even though this fixes the problem, I'd rather create a symbolic link instead of copying the folder. This way, if something changes in the `jbr` folder, you don't need to copy the folder again. In the step 2, just type `ln -s jbr jre`. This will fix the problem. – Javi Jan 21 '23 at 09:52
  • 1
    re: soft link solution. Terminal app on Mac OS doesn't have full disk access by default which means you won't be able to create a soft link, even with a sudo. Full Disk access can be granted under System Settings under Privacy & Security. – Alex S Jan 25 '23 at 07:08
  • thx, this is really works for me. – ahmfarisi Aug 18 '23 at 23:23
52

Here is a little fuller answer for everything I had to do to get Android Studio set up on my M1.

  1. Install Android Studio to the Applications folder

  2. Create a symbolic link to from the jre folder to a new jdk folder. (Due to this bug)

cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
  1. Set the JAVA_HOME environment variable
nano ~/.zshrc
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
source ~/.zshrc
  1. Install Android SDK Command-line Tools (needed for accepting license)

  2. At this point it should work now (assuming you've also added flutter to your path)

flutter doctor
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • The `command-line tools` is important for accepting the packages – rookieDeveloper Aug 17 '21 at 10:32
  • I faced similar issue on non M1 mac. The above solution fixed. Seems like its not related to M1 chip. This simple hack solved the issue with "file bundle with java not found". – Abhishek Sachan Sep 04 '21 at 11:14
  • There is no `jdk' directory inside `/Applications/Android Studio.app/Contents/jre/` on my machine though. I'm also on a M1 Mac. Any idea what I might be missing? – Isuru Sep 10 '21 at 11:57
  • @Isuru, Right, that's the problem. Writing `ln -s` creates the `jdk` directory as a soft linking pointing to the existing `jre` directory. – Suragch Sep 11 '21 at 00:46
  • This works for me – Shift 'n Tab Sep 29 '21 at 20:50
18

This is the Windows fix, and it appears to work for me. I am using Android Studio2022.1.1.19

  1. First, right-click the Android Studio icon and open the file directory(location). Your installation folder should be at "C:\Program Files\Android\Android Studio".
  2. When you are already at the Android Studio installation root folder, you will see two folders: "jbr" and "jre".
  3. Copy all the files inside the "jbr" folder to the "jre" folder, then try it again.

Note: This fix is working on my end; just comment down below if it didn`t work on your end.

Clinton Canarias
  • 409
  • 4
  • 15
10

In my case, on a macOS Ventura with Intel processor, I had to follow the steps below in order to make Flutter work after upgrading Android Studio to Electric Eel:

  1. cd /Applications/Android\ Studio.app/Contents/
  2. ln -s jbr jre
  3. flutter config --android-studio-dir /Applications/Android\ Studio.app/Contents

Step 3 was important, without it flutter doctor --android-licenses would always fail...

ldlgds
  • 123
  • 1
  • 7
6

I did install a fresh version of JAVA SDK, flutter, Android Studio and run the below command directly on the terminal one by one to fix 'Unable to find bundled Java version. ' issue.

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

  2. ln -s ../jre jdk

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

  4. flutter doctor -v

Now, you should be able to see the error is disappeared in flutter doctor description in terminal.

Mir Mumtaz
  • 109
  • 2
  • 9
4

Run Flutter doctor, if there´s an error indicating that the java bundled can´t be found (specially if you have Android Studio version Artic Fox), run this commands if using Mac:

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

  2. ln -s ../jre jdk

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

  4. Flutter Doctor

Kaushik Godhani
  • 181
  • 1
  • 2
  • 6
4

This solution is for M1 Mac User

  1. Find your local Java version by typing /usr/libexec/java_home -V. If didn't exist, install the latest ARM Java version here
  2. Set Java_Home path (in my case jdk-17.0.1.jdk) by typing /usr/libexec/java_home /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home
  3. Type all of these in terminal
cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
  1. Finally run flutter doctor -v to see all the details changes
Alphapico
  • 2,893
  • 2
  • 30
  • 29
  • I typed `zsh: permission denied: /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home` into Terminal, hoping to set the Java_Home path and it said `permission denied /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home`. Is there somewhere else I should type? How do I give it permission? – Sam Jan 14 '23 at 14:51
  • You can us sudo: `sudo export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home` or chown `sudo chown -R $(whoami) /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home` This will give you the ownership of the directory, so you don't have to use sudo everytime you want to access it. – Alphapico Jan 15 '23 at 07:21
4

Works on macOS This will link jbr folder to jre

cd /Applications/Android Studio.app/Contents

or

cd /Applications/Android\ Studio.app/Contents

ln -s jbr jre

Result:

enter image description here

ANDYNVT
  • 531
  • 4
  • 19
2

I had the same error after updating Android Studio to 2020.3.1 Patch 3 (on MAC).

After upgrading Flutter from 2.2.2 to 2.5.3 problem was solved.

I also installed "Android SDK Command-line Tools". It's installation is explained here: https://stackoverflow.com/a/68492909/6839552

2

The accepted solution worked with a slight modification for me. I had to add the -f (or use --force) option to make it work (this is because ln failed with file exists and I kept ignoring that - the existing file must have had a problem).

cd /Applications/Android\ Studio.app/Contents/jre
ln -s -f ../jre jdk
ln -s -f "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk

flutter doctor -v

I'm running macOS Monterey

Stephen Nyamweya
  • 104
  • 1
  • 11
1

Perhaps the simplest option (MAC):

  • Navigate to: cd /Applications/Android\ Studio.app/Contents/jre
  • Create a directory: mkdir jdk
  • Create a soft link: ln -s Contents jdk/Contents
Dieter
  • 33
  • 3
0

COPY folder /Applications/Android Studio Preview.app/Contents/jre/Contents to /Applications/Android Studio Preview.app/Contents/jre/jdk/Contents

crzorz
  • 1
  • 1
  • This workaround might violates standard AS default JAVA_HOME directory, have you already tried in your local? – mochadwi Jul 29 '21 at 03:14
  • 1
    You can check this script code,YOUR_PATH/flutter/packages/flutter_tools/lib/src/android/android_studio.dart,and find the code just like this `globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home')`, then you can get what path you should set for the "doctor" – crzorz Jul 29 '21 at 03:19
0

It's @crzorz 's additional answer worked for me. "YOUR_PATH/flutter/packages/flutter_tools/lib/src/android/android_studio.dart". At the bottom of the file, you'll see lines similar to "globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home')" which @crzorz mentioned.

These lines clearly show on MacOS (old and new versions) and other OS how "flutter doctor" finds the so-called bundled Java.

I use Android Studio Electric Eel. What I did to fix the issue was "create a symbolic link named jre pointing to jbr". Because folder jbr (JetBean Runtime) has the java.exe and other Java Runtime files, but flutter doctor still tries to find a folder named jre.

0

Update to:

Android Estudio 2022.1 Electric eel + Java 19 + VS Code + Windows 10 x64

Before: Make sure you have JAVA_PATH correctly

1 - Run CMD as Administrator [Not POWERSHELL, because mklink only work for CMD]

2- Run the mklink /d "C:\Program Files\Android\Android Studio\jre" "C:\Program Files\Android\Android Studio\jbr"

3- Run command flutter doctor and Problem solved, but then apears the licenses problem, so

4- Run command flutter doctor --android-licenses wait and accept all

Other way doesn't work, thrown a error: " bla bla bla...already exist..." why?

Because the structure of mklink command: mklink [OPTIONS: /d /j /h rd del] "Path+Name folder/file you want {jre}" "Path+Name folder/file linked {jbr}"

Traduced to human language: Make a Symbolic link [mklink /d] "there with the name jre" to the folder "that is there with the name jbr"

Make sure to use "double quotes" for the files paths and say "please" and not "Just do it" (cmd smell your hurry).

If you dont do it like this, will have problems with sdkmanager and launch devices, because the new Android Estudio don't use jre and that's why many android devices don't launch, and have the 60 second problem.

0

Copying all contents of JDK and pasting it into a JRE file, worked for me.

After that, I updated my ENV path.

ZaxLofful
  • 1,034
  • 9
  • 18
Yash
  • 1
  • 2