Explain Codes LogoExplain Codes Logo

Failed to install android-sdk: "java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema"

java
java-8
android-sdk
java-opts
Nikita BarsukovbyNikita Barsukov·Nov 21, 2024
TLDR

The NoClassDefFoundError for javax/xml/bind/annotation/XmlSchema could be fixed by introducing JAXB. It is not included by default in Java 11+. For Maven projects, add:

<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.1</version> </dependency>

Gradle projects require:

implementation 'javax.xml.bind:jaxb-api:2.3.1'

These dependencies should resolve the classpath issue for the Android SDK installation.

Getting Android SDK ready

Set up PATH for Android SDK Tools

After installing Android SDK Command-line Tools (latest), add the path of these tools to PATH environment variable.

export PATH="$HOME/Library/Android/sdk/cmdline-tools/latest/bin:$PATH"

Keeping it Java 8

The Android SDK may not play nicely with Java 9+. Switch back to Java 8 for the android sdk compatibility.

Uninstall Java 9 (or above), install Java 8:

brew cask uninstall java brew tap adoptopenjdk/openjdk brew cask install adoptopenjdk8

Accepting licenses

Run flutter doctor --android-licenses and hit 'y' when prompted.

flutter doctor --android-licenses

All licenses should be accepted post installation or updates of Android tools.

Guide to setup environment

Acquaint yourself with Android SDK Tools

Know your Android SDK directory path and SDK Tools in Android Studio:

File > Settings > Languages & Frameworks > Android SDK > SDK Tools

Ensure all necessary SDK tools are installed and visible here.

Taming Java with options

For Java 8, you may need to export additional Java options:

export JAVA_OPTS="$JAVA_OPTS --add-modules java.se.ee"

Persist these settings by adding them to your .bashrc or .zshrc file.

Verify your installation

Confirm successful installation by running the sdkmanager command. It responds by listing the installed packages in your SDK, else displays the error.

sdkmanager --list

In case of errors, create a repositories.cfg file in .android directory. Sometimes, errors are due to missing cfg files.