Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix sdkmanager java.lang.NoClassDefFoundError batchfile [duplicate]

I get an error trying to run sdkmanager

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(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 5 more

How can I fix this as I have tried changing to Java 7, 8 and 10, but none is working.

like image 406
D. Sikilai Avatar asked Mar 30 '19 23:03

D. Sikilai


Video Answer


2 Answers

I had the issue as default installation of java was v11

java -version
Should be : openjdk version "1.8.0_252"

Fix:
sudo apt-get install openjdk-8-jdk
Don't worry won't overwrite
Then switch to the correct version via
sudo update-alternatives --config java

confirm correct output from java -version

than run sdkmanager again.

like image 97
Aron Edwards Avatar answered Sep 18 '22 12:09

Aron Edwards


You can try this solution

First open sdkmanager.bat with any text editor

Then find this line

  %JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS%

And change it to this line

  %JAVA_EXE%" %DEFAULT_JVM_OPTS% --add-modules java.xml.bind %JAVA_OPTS% %SDKMANAGER_OPTS%

I hope this solves your problem.

like image 24
Amine Avatar answered Sep 20 '22 12:09

Amine