flutter doctor –android-licenses gives a java error

After installing flutter on my development environment, I face flutter doctor android license issue while I was checking the installation with below command:

flutter doctor --android-licenses
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

That was not the expected result as I follow the installation instructions step by step documented on flutter official site.

I could successfully fix the issue by simply install install Android SDK command line tool from the Android SDK Manager, in order to do that, follow the below steps

  1. Start Android Studio
  2. Go to Tools > click on SDK Manager
  3. From the left-hand side choose, Appearance & Behavior then System Settings then Android SDK
  4. from the tabs, Select SDK Tools 
  5. Check Android SDK Command-line tools 
  6. click ‘apply’.

Below screenshot is showing the settings popup (I have dark theme on Android Studio)

Android Studio – Settings popup

If you are still facing issues after applying above steps, consider upgrading JDK to the latest. here is the Java official upgrading JDK 8 (latest at this moment)