340
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 5 more

I get this error above when running flutter doctor --android-licenses. Does anyone know why this is happening and how I can fix it? I'm already running it on the flutter console.

15 Answers 15

721

Installing Android SDK Command-line tools from Android SDK Manager did the job for me.

  1. Open Tools > SDK Manager
  2. From the left choose, Appearance & Behavior > System Settings > Android SDK
  3. Select SDK Tools from the top menu
  4. Check Android SDK Command-line tools and click 'apply'.

Alternative to step #1: WINDOWS: File > Settings (Ctrl+Alt+S) / MAC : Android Studio > Preferences

This fix works for Windows, Linux and Mac OS X.


enter image description here

If you are facing a problem in spite of the above steps, you can try upgrading your system to JDK 8. Official documentation of upgrading to JDK 8 is available here.

8
  • 9
    Thanks! This solves the problem, but why? If flutter doctor needs SDK command-line tools, why isn't the tools packed with flutter? Commented Dec 15, 2020 at 13:25
  • 5
    'Android SDK Command-line tools' is an Android SDK package tool and comes with your Android Studio (RE: developer.android.com/studio/command-line). It cannot be included in flutter installation.
    – sariDon
    Commented Dec 16, 2020 at 4:38
  • 2
    Apparently this is required on MacBook but not on Windows. I don't have the command line tools set in windows.
    – Syed Ali
    Commented Jan 14, 2021 at 23:58
  • 15
    I faced the problem in Windows environment
    – sariDon
    Commented Jan 15, 2021 at 6:53
  • 2
    Counterintuitively, this solution fixes the problem even for people who use VS Code for development.
    – Stefan
    Commented Aug 30, 2021 at 16:27
166

I'm a Mac user and I solve this issue.

This answer also helps Windows users and Linux users solve the issue from the user's feedback.

At the first, this is what I met for the issue
$ flutter doctor -v enter image description here

And the following command is not work for my situation.
$ flutter doctor --android-licenses enter image description here

The way to solve this is to install
Android SDK Command-line Tools. And how?
You just need to do it by the following two steps.

Install: Android SDK Command-line Tools

Step 1. Open SDK Manager
Top Menu -> Tools -> SDK Manager enter image description here

Step 2. Install command-line tools

  1. Unfold Appearance & Behavior
  2. Unfold System Settings
  3. Click Android SDK
  4. Click tab of SDK Tools
  5. Check Android SDK Command-line Tools (latest)
  6. Click Apply button. enter image description here Then click OK button to finish installation.

Keep going to sign android licenses.

After Android Studio finishing install, you can do the following.
$ flutter doctor --android-licenses
enter image description here After saying yes many times, all android licenses have been signed.

Check by flutter doctor again.

$ flutter doctor -v
enter image description here

You can see that All Android licenses accepted.

Congratulations, you have completed this task!

12
  • 3
    Works on Windows. Thanks.
    – yoadev
    Commented Jul 13, 2021 at 17:00
  • 3
    Works on linux as well.
    – Marcin
    Commented Jul 20, 2021 at 4:13
  • 2
    Worked on MacBook M1 ✅🔥 Commented Jul 31, 2021 at 13:01
  • 2
    Worked on Pops!_OS Commented Aug 8, 2021 at 11:02
  • 1
    I wish more answers would have such nice pics and step to step instructions! Thanks
    – Alessio
    Commented Aug 22, 2021 at 6:23
63

i had the same problem, solved it by installing the coomand-line tools from android studio

click on file, settings then on the search bar type sdk and click in android sdk Android Sdk

Then click on sdk tools, check the android command-line tools box, the click on apply allow to download. then try running flutter doctor --android-licenses again on your cmd you will be prompted to accept licenses

1
  • 1
    On a mac, the settings window is found under Android Studio -> Preferences
    – rawbee
    Commented Jun 9, 2021 at 0:54
22

It seems you are getting a JDK exception, it happens when you does not have JAVA_HOME setted on your system variables OR you have almost setted the JDK but in the wrong folder OR you are trying to run the SDK Manager (which allows you to accept the Android Licenses) with the wrong JDK.

In case of JDK 9 or higher:

Actually, Android SDK Manager works only with Gradle compiled on version of JDK 8 for Android development, so, if you have a most-recent JDK version already setted on system variables, consider to downgrade it to the JDK version 8.

This version works fine for me: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

In case of JDK 8 already installed

If you manually extracted the JDK folder to a directory, maybe you have setted it "wrong". I mean: You pointed the wrong way to the bin Java folder, but it still works. You have to set JAVA_HOME as the root of JDK, example: In the JDK zipped folder, you have to extract it and point the system variable in the unzipped folder, no directly in the bin directory, you have to point JAVA_HOME as a system variable and declare the bin folder as an executable.

Examples:

Linux

In your shell configuration file:

export JAVA_HOME="/home/user/jdk1.8.0_261"
export PATH="$PATH:$JAVA_HOME/bin"

Windows

In your environment variables manager:

Set a new SYSTEM VARIABLE named JAVA_HOME

enter image description here

Then, edit the PATH variable and add a new register to it:

%JAVA_HOME%\bin

Actually, I don't know really how to manage JDKs in MacOS, if that is you OS, sorry :(

Hope it helps!

2
  • 1
    This solution does not work for me on windows 10 Commented Feb 24, 2021 at 8:44
  • 1
    This solved the issue for me on Windows 10, thank you! Worth noting that the reference JDK 8 works, which doesn't require the much heavier Oracle license. Still seems strange that Android Studio ships with Java 11, but the SDK tools still needs Java 8. Commented Jul 16, 2021 at 1:57
5

On Linux

Android SDK only works with JDK 8 so uninstall your current JDK version.

Past the command and press tab for autocomplete, remove all the things that it shows you that starts with openjdk-

sudo apt remove openjdk-

and now install JDK 8

sudo apt install openjdk-8-jdk
3

first of all you need to know that flutter works on jdk 8, so if you have other versions installed you need to purge them so as to completely remove other versions

NOTE: this is according to my case Ubuntu 20.04, THIS IS ACCORDING TO MY SITUATION IT IS NOT GUARANTEED TO WORK FOR YOU

if you have jdk 11, to uninstall use one of the two commands depending on the one that you had installed or you can run both of them if you do not know which one of them is installed on your machine.

sudo apt purge openjdk-11-jre-headless

sudo apt purge openjdk-11-jre

if it is any other version replace 11 with that number. if you use the default jdk then to uninstall use the following command

sudo apt purge default-jre

to make sure we remove everything related with java run this command

sudo apt auto remove

NOTE: you can run all the above commands just to be more sure you fully remove everything related with java

to verify that we have removed everything run

java -v

if you see the error below or java version then java has not been uninstalled

Unrecognized option: --version
Error: Could not create the Java Virtual Machine. 
Error: A fatal exception has occurred. Program will exit.

but if you get response that java was not found and there are java installation suggestion it means java has been uninstalled

now we need to install jdk 8 run this command

sudo apt install openjdk-8-jre

if everything goes well reboot your machine and run flutter doctor and follow the instructions to accept the licenses

Regards, hope this post becomes helpful to you

2
  • an addition to uninstalling the existing java version you can also use sudo apt purge openjdk* to uninstall any existing version of java, then execute sudo apt autoremove to clear and remove any java related components on the system
    – Abdulbasit
    Commented Mar 23, 2021 at 13:35
  • 1
    I don't think it's a good idea to remove and then re-install a new specific Java version just for the purpose of having flutter doctor --android-licenses work. Actually, it's more appropriate to switch to another Java version if you have multiple versions of Java installed, by exporting the desired one. for example:export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/. Internally, flutter doctor will check JAVA_HOME for the target Java version. The benefit is obvious, the one-time export command in a command line window won't affect anything else at all.
    – Neil.Ling
    Commented Feb 16, 2023 at 2:34
3

For me, on Windows 10, the answer was simply to remove the JAVA_HOME environment variable.

This probably isn't a good idea if you're a Java developer, or you rely on some Java software to do your work, but if you're a dev that doesn't work in the Java space and you're just getting started with Flutter like I am, then go into the system environment variables and kill that one. flutter doctor --android-licenses worked like it is supposed to after I did that.

1
  • weird! worked for me as well. thank you! was stuck for several hours... Commented Feb 6, 2023 at 21:54
3

I found I needed to downgrade my Android SDK Command Line Tools

When I was on the latest then flutter doctor --android-licenses gave the following:

$ flutter doctor --android-licenses
Error: LinkageError occurred while loading main class com.android.sdklib.tool.sdkmanager.SdkManagerCli
    java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/sdkmanager/SdkManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
Android sdkmanager tool was found, but failed to run (/Users/user/Library/Android/sdk/cmdline-tools/latest/bin/sdkmanager): "exited code 1".
Try re-installing or updating your Android SDK,
visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions.

Then I removed Android SDK Comand-lin Tools (latest) (11) and added version 10.

enter image description here

Only then could I accept the licenses:

$ flutter doctor --android-licenses
Warning: Observed package id 'ndk-bundle' in inconsistent location '/Users/user/Library/Android/sdk/ndk-bundle.backup.version_17c' (Expected '/Users/user/Library/Android/sdk/ndk-bundle')
Warning: Observed package id 'ndk-bundle' in inconsistent location '/Users/user/Library/Android/sdk/ndk-bundle.backup.version_17c' (Expected '/Users/user/Library/Android/sdk/ndk-bundle')
[=======================================] 100% Computing updates...             
All SDK package licenses accepted.
1
  • 1
    Nice downgrading to version 10. Worked for me thanks
    – Plaximo
    Commented Nov 30, 2023 at 17:51
2

My solution was: I had Android SDK Build-Tools, Android Emulator and Android SDK Platform-Tools installed. Also I had JAVA_HOME variable in environments variables.

So I decided to uninstall Android SDK Build-Tools, Android Emulator and Android SDK Platform-Tools and install them again. Moreover, I deleted JAVA_HOME variable. And after these operations I run flutter doctor --android-licenses in terminal. And somehow it worked out.

1

The above solutions totally work, but there's a solution that I see fewer times than I would expect: sdkman => https://sdkman.io/

with such a tool installed, changing java version is quick as ( Adopt java 8 as example):

❯ sdk install java 8.0.282.hs-adpt
❯ sdk use java 8.0.282.hs-adpt
1

Just in case you have multiple versions of Java installed on your OS, and the active Java version is higher than the expected one, you may end up with UnsupportedClassVersionError exception.

In my MacOS case, the active Java version is Java 17.

~ java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment Zulu17.38+21-CA (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Zulu17.38+21-CA (build 17.0.5+8-LTS, mixed mode, sharing)

and the expected Java version is Java 11 as of now.

so my flutter doctor --android-licenses command ended up with following error:

flutter doctor --android-licenses
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
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

Obviously, Java 11 (class file version 52.0) rather than Java 17(class file version 55.0) is required.

Solution is exporting JAVA_HOME (preferred in a command line windown) and run flutter doctor --android-licenses again, then it should work.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/
flutter doctor --android-licenses

By the way, installed Javas can be detected by Android Studio. enter image description here

(Pasted my previous comment) Again, I don't think it's a good idea to remove and then re-install a new specific Java version just for the purpose of having flutter doctor --android-licenses work. Actually, it's more appropriate to switch to another Java version if you have multiple versions of Java installed, by exporting the desired one. for example:export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/. Internally, flutter doctor will check JAVA_HOME for the target Java version. The benefit is obvious, the one-time export command in a command line window won't affect anything else at all.

2
  • Java is up to its old whacky tricks eh?? Emphasizing that last paragraph was good. I get what you're saying... I might have gone against that if you hadn't said it! Now I need to go look up what this zulu thing is all about. Why can't Java behave?!? Commented Mar 25, 2023 at 19:35
  • A great solution to save my life for adding missing JAVA_HOME to ~/.zshrc.
    – mondayrris
    Commented Apr 5, 2023 at 0:27
0

Android Studio Electric Eel and Flutter 3.7.1
If you're facing issues after upgrading to Android Studio Electric Eel then these additional steps might help you. Usual errors after upgrading to the aforementioned Android Studio version are:

  • unable to locate android sdk

  • 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

  • Follow the procedure described here for installing Android SDK Command-line tools and Android SDK Manager.

  • Download Java JDK 19 or JDK 17 from here.

  • Based on the error you're getting e.g. file versions up to XY.0 you might need to install a different Java version. You can find more details on which Java version to install on Oracle - Class file format major versions and a related discussion on StackOverflow - List of Java class file format major versions.

  • Install the JDK on C:\Program Files\Java\java-sdk-[version].

  • Update your JAVA_HOME to point to the JDK. This can be achieved though the Edit System Environment Variables -> Environment Variables. You can find more on how to set the JAVA_HOME variable on Oracle - How to set the JAVA_HOME variable.

After these steps are followed, open a fresh command line and run flutter doctor --android-licenses. The error should be now resolved.

0

All I had to do was to unset JAVA_HOME. Then it worked.

0

I have followed everything that is mentioned in @Milo Chen answer but could make it work for my linux system (Ubuntu-22.0 lts,java 17 openjdk,javac 11) so here is my workaround to solve the issue

  • I download the Android Sdk Command-line tools version 8 (you need to check Show Package Details checkbox to get that version in Android studio)
  • go to your the folder where android studio store its sdk file, for me it's /home/mirsahib/Android/Sdk/cmdline-tools
  • rename the folder 8.0 to latest
0
  • Uncheck Android SDK command-line Tools (latest)
  • Check Android SDK command-line Tools 8.0
  • Click Apply
  • In Windows, go to “C:\Users\USERNAME\AppData\Local\Android\Sdk\cmdline-tools” and rename the 8.0 folder to “latest”

Run Flutter doctor again.

Not the answer you're looking for? Browse other questions tagged or ask your own question.