15

I am trying to accept flutter doctor --android-licenses but I am getting this error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/prefs/AndroidLocationsProvider has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Elijah Mock
  • 587
  • 8
  • 21
Ajay Jha
  • 149
  • 1
  • 1
  • 6
  • So it looks that you have java 8 installed (class version 52) but this flutter version requires java 11 ( version 55) so easiest solution would be to update java on your machine. – bongo Feb 02 '23 at 19:38
  • I faced the same problem, please help me find a solution – Daniil Feb 06 '23 at 05:44
  • Maybe there are two java versions installed on your system. – Ajay Jha Feb 06 '23 at 06:38
  • export JAVA_HOME=$(/usr/libexec/java_home -v"YOUR_VERSION") use this command it will be resolved – Ajay Jha Feb 06 '23 at 06:39

9 Answers9

12

I'm on MacOS Ventura. I installed Android Studio today. This is how I solved the problem:

  1. Downloaded JDK19
  2. Followed the steps mentioned at this link
  3. Since I'm running Android Studio Electric Eel, opened Terminal and ran this command cd /Applications/Android\ Studio.app/Contents/jbr
  4. Then ran this command after ln -s ../jbr jdk
  5. And finally, ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
  6. Went to Finder -> Applications -> Android Studio. Right-click Android Studio and select 'Show Package Contents'
  7. Created new folder 'jre' in folder 'Contents'
  8. Copied contents from the 'jbr' folder to the 'jre' folder
  9. Ran flutter doctor again
  10. Ran flutter doctor --android-licenses.

I was able to agree to the licenses successfully after.

All the steps are also mentioned here and here

AyeshaA
  • 141
  • 7
7

UPDATE

It turns out there are 2 JDK installed in my environment, you can check by using

/usr/libexec/java_home -V

so after removing the older JDK version, the issue is fixed.


Having the same error, although here is my java --version output

java 19.0.1 2022-10-18
Java(TM) SE Runtime Environment (build 19.0.1+10-21)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

this happens after I upgrade to flutter 3.7.1

pddthinh
  • 141
  • 6
  • How did you remove the older JDK version? What commands? – Pathros Feb 05 '23 at 18:56
  • 2
    @pathros, from the `/usr/libexec/java_home -V`, you will find the path to the older JDK version, then just use the `sudo rm -rf ` to remove it – pddthinh Feb 06 '23 at 13:55
7

I've had the same error, I haven't specify JAVA_HOME env, and flutter used my 1.8 java.

For macOS: Check your JAVA_HOME env in terminal with

printenv

if env not existed, list installed java version

/usr/libexec/java_home -V

choose one and execute

export JAVA_HOME=$(/usr/libexec/java_home -v"YOUR_VERSION")
marc_
  • 105
  • 1
  • 7
5

There is a simple way to resolve this issue.

  • Check java version you installed on your machine. If it is version 8, Installed Android SDK Command-line Tools 8.0 & uninstalled latest version. enter image description here
Abhay
  • 6,410
  • 4
  • 26
  • 34
  • this is simplest way...thanks, @Abhay! also, if you cannot see all the versions installed, click the Show Package Details checkbox at the bottom. – braingraze Mar 28 '23 at 19:20
  • That did not work for me. I kept getting a corrupted SDK error until I manually downloaded and installed JDK 20 and set JAVA_HOME to point to it. – Dieter Donnert Jul 28 '23 at 02:13
3

Try This (For Windows)

  1. Uncheck Android SDK command-line Tools (latest)
  2. Check Android SDK command-line Tools 8.0
  3. Click Apply
  4. In Windows go to “C:\Users\USERNAME\AppData\Local\Android\Sdk\cmdline-tools”
    and rename the 8.0 folder to “latest”
  5. Run Flutter doctor again.
  • Solution worked great. For some additional information for ease: if you are in Android studio, then you go to the more actions -> SDK manager -> and then if you check off "Hide Obsolete Packages" and "Show Package Details" then you should be able to find SDK command-line tools 8.0 in the command line tools. – Joginder Malik Mar 25 '23 at 10:44
1

You can run the following command to see if you have multiple java versions:

/usr/libexec/java_home -V

In my case, I had 2 versions on my mac: java 8 and java 19. I followed the official java website to remove my older version:

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
1

The problem seems to be when the android studio installed is Android Studio Electric Eel

All you have to do is:

  1. Follow this link and ddownload - install this jdk https://www.oracle.com/java/technologies/downloads/#jdk19-mac
  2. After installing, goto Finder -> Applications -> Android Studio. Right-click on Android Studio and select 'Show Package Contents'
  3. Open the Contents folder and create new folder and name it jre
  4. There's a folder named jbr open it and copy the folder inside it and paste it into your newly created folder on step 3 (jre).
  5. You can now be able to accept the licences by running- flutter doctor --android-licences
ABI
  • 11
  • 2
0

In my case on Windows the reason was that Flutter searched Android SDK Command-line tools under sdk folder instead of Sdk.

user128440
  • 179
  • 2
  • 7
0

I found a simple solution to the problem - by updating the JDK directly and then reinstalling Android Studio. I faced a similar issue initially, i use windows 10 pro and here's how I resolved it:

  • Check for updates for Flutter. In my case, I was using version 3.10.6.
  • Verify and update the JDK installed on your system. I upgraded from Java 8 to Java 20.0.2.
  • Update Android Studio to the latest version. I was previously using Electric Eel and updated to Giraffe.
  • Re-download the SDKs. I had initially downloaded them while on the Electric Eel version, and upon updating, I found that the SDKs didn't need to be updated separately. This saved me some time. During the uninstallation of Electric Eel, I didn't delete the SDK cache.
  • Run flutter doctor -v again and accept android licenses by flutter doctor --android-licenses.

It's important to note that Flutter only functions with the most up-to-date version of JAVA, which is closely tied to the version of Android Studio you're using.

XanderOps
  • 1
  • 1