Skip to content

Instantly share code, notes, and snippets.

@dnedrow
Last active July 24, 2023 14:34
Show Gist options
  • Save dnedrow/8c8a4cbd4b713c5bd40c369396036f0b to your computer and use it in GitHub Desktop.
Save dnedrow/8c8a4cbd4b713c5bd40c369396036f0b to your computer and use it in GitHub Desktop.
Solving Android tools `java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema` error

The Problem

When using new versions of Java (anything higher than 1.8), you may see the following error when attempting to use any of the SDK tools, e.g. sdkmanager...

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

Starting with Java 9, the XmlSchema library is not included in the base JDK.

To get around this, many people will resort to downgrading to JDK 1.8. This is unneccesary.

Here is how to resolve the error on macOS. The procedure and file locations will vary on different platforms.

  1. In the Android Studio settings, navigate to SDK Tools. Generally, the path to this is...

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

  1. In the SDK Tools tab, select the Android SDK Command-line Tools (latest) option.
  2. Click Apply and Close to install the updated tools.

That's all that needs done in Android Studio. To make use of the updated tools, you'll need to add them to your path.

I typically use the following block in my shell rc file, e.g. ~/.zshrc...

export ANDROID_HOME="${HOME}/Library/Android/sdk"
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_AVD_HOME="${HOME}/.android/avd"

PATH="${ANDROID_HOME}/platform-tools${PATH:+:${PATH}}"
PATH="${ANDROID_HOME}/tools${PATH:+:${PATH}}"
PATH="${ANDROID_HOME}/cmdline-tools/latest/bin${PATH:+:${PATH}}"

export PATH

NOTE

If you have ${ANDROID_HOME}/tools/bin being added to your path, remove that addition. The updated tools are installed in ${ANDROID_HOME}/cmdline-tools/latest/bin.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment