26

Using sdk-tools-darwin-4333796 (26.1.1) with Java 9 when running sdkmanager is throwing :

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
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Aero Wang
  • 8,382
  • 14
  • 63
  • 99
  • I think java 9 doesn't contain this file path to the specified file. Take a look at this similar question. It might help you with your problem. https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j – Umair Nov 17 '17 at 07:12
  • Yes with `./sdkmanager --add-modules java.xml.bind` it does run without error but meanwhile it doesn't allow me to add any arguments to it (like `./sdkmanager --version --add-modules java.xml.bind` would simply bring up manual. – Aero Wang Nov 17 '17 at 07:26
  • @AeroWang `Warning: Unknown argument --add-modules` at my install. – Eugene Gr. Philippov Aug 21 '19 at 06:55

1 Answers1

33

Edit sdkmanager file, find DEFAULT_JVM_OPTS and add --add-modules java.xml.bind argument to it.

For instance, if your sdkmanager file has

DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME"'

change it to

DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" --add-modules java.xml.bind'

Update: the above works for Java 9 and 10. The java.xml.bind module was removed in Java 11, and will not be found.
https://www.oracle.com/java/technologies/javase/jdk-11-relnote.html#JDK-8190378


Additional Update: Apparently there are two versions of the sdkmanager, a deprecated one that requires Java8 and a new one that works with Java 11. See this answer on StackOverflow

dsh
  • 12,037
  • 3
  • 33
  • 51
James Wayne
  • 1,894
  • 14
  • 14
  • 2
    Thanks for this. While you're there, it's worth making the same change to ./avdmanager too. – Nige Jones Jan 01 '18 at 15:55
  • 3
    Thank it works for me. I have changed like below : DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" --add-modules java.xml.bind' – Bhushankumar Lilapara Mar 20 '18 at 06:32
  • 1
    You can also set instead the JAVA_OPTS environment variable to the same value, without the need to modify the scripts. – wvengen Jun 04 '18 at 11:32
  • Thank you so much! It works for me. [Arch Linux x64 - OpenJDK 10] – Dentrax Jul 10 '18 at 22:28
  • 11
    Didn't work for me. I get Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found – cyril Jan 09 '19 at 14:47
  • 2
    Unfortunately this does not work anymore. The weird thing is that you can run SDK Manager from the Android Studio GUI and it seems to work fine. – Oscar Feb 07 '19 at 23:33
  • It throws error "Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found" – Sohail Mar 23 '19 at 23:15
  • me too: Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found – Gauthier Buttez Sep 07 '20 at 17:18