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.
- In the Android Studio settings, navigate to
SDK Tools. Generally, the path to this is...
Settings > Languages & Frameworks > Android SDK > SDK Tools tab
- In the
SDK Toolstab, select theAndroid SDK Command-line Tools (latest)option. - Click
ApplyandCloseto 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.