61

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,032
  • 3
  • 18
  • 34
Mohamad Faris
  • 713
  • 1
  • 5
  • 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

9 Answers9

174

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
Etienne Kaiser
  • 2,634
  • 8
  • 19
  • 29
Miktad
  • 1,901
  • 1
  • 5
  • 14
  • 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
49

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
  • 428,106
  • 278
  • 1,284
  • 1,317
  • 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 – Roel Sep 29 '21 at 20:50
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
  • 111
  • 2
  • 9
3

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

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

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
X Sham
  • 2,581
  • 2
  • 26
  • 28
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

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