I am trying to build my first android studio project. I keep getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
When I try to build the simplest "MyFirstApp" project, I do not get this error.
I have tried to run the sdkmanager
from the terminal:
cd /Users/username/Library/Android/sdk/tools/bin
./sdkmanager --licenses
as well as by physically going to the sdkmanager directory, and double clicking on sdkmanager
.
I get the same error on both. I also updated my Java. So, why do I get this error? And how do I fix it?
The full error is as follows:
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:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more
Also, just adding it here, in case it is relevant, this is the output I get when running java --version
:
java 13.0.2 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
I checked the gradle sync inside Android Studio itself, and I found there was another error there:
ERROR: Module 'app': platform 'android-29' not found.
This was probably because I had downloaded the latest Android version, which is Android R (aka Android 30 in Android Studio), while this project probably expected version 29 (Android Q). So, once I downloaded and installed Android 29, by going to Tools -> SDK Manager, and restarted Android Studio, it works fine and does not give any error.