Android: Error when execute sdkmanager

Quick fix for error that sdkmanager throw exception when trying to call sdkmanager –license and sdkmanager –list.

Error messages

1
2
3
4
5
6
7
8
9
10
11
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:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 5 more

Quick fix

In Windows:

  1. Go to C:\Users\Alex.Li\AppData\Local\Android\Sdk\tools\bin
  2. Open sdkmanager.bat with editor
  3. Add -XX:+IgnoreUnrecognizedVMOptions –add-modules java.se.ee after set DEFAULT_JVM_OPTS=”-Dcom.android.sdklib.toolsdir=%~dp0..”:
    1
    set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.." -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee

In Linux:

  1. Go to <android_sdk_path>/tools/bin, <android_sdk_path> is the path where you unzip your Android SDK.
  2. Open sdkmanger with editor
  3. Add -XX:+IgnoreUnrecognizedVMOptions –add-modules java.se.ee after DEFAULT_JVM_OPTS=’”-Dcom.android.sdklib.toolsdir=$APP_HOME”‘“:
    1
    DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'