Failed to install android-sdk: "java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema"
Solution 1
I had a similar problem this morning (trying to build for Android using Unity3D). I ended up uninstalling JDK9 and installing Java SE Development Kit 8u144. Hope this helps.
-
brew cask uninstall java
# uninstall java9 brew tap homebrew/cask-versions
-
brew cask install java8
# install java8 -
touch ~/.android/repositories.cfg
# without this file, error will occur on next step brew install --cask android-sdk
Solution 2
Just had this error, solved by downloading the Android SDK Command-line Tools (latest)
on Android Studio, under Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools
and re-running flutter doctor --android-licenses
Finally, add the new tools to your PATH, in your .bashrc
, .zshrc
or similar, before the obsolete tools:
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
Solution 3
- I also had this error
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:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 5 more
- then instead of uninstalling the latest java environment, (in my case it is java 13)
- and installation of
java 8
, - I have done the following steps
open the android studio > go to configure > select sdk manager > go to sdk tools > make a tick on android sdk command line tools >apply > and wait for installation
-
enter the command
flutter doctor
-
enter the command
flutter doctor --android-licenses
-
and accept all the licenses by typing
y
.
Solution 4
To solve this error, you can downgrade your Java version.
Or exports the following option on your terminal:
Linux/MAC:
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Windows:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
If this does not work try to exports the java.xml.bind
instead.
Linux:
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind'
Windows:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind
And to save it permanently you can exports the JAVA_OPTS
in your profile file on Linux (.zshrc
, .bashrc
and etc.) or add it as an environment variable permanently on Windows.
ps. This doesn't work for Java 11/11+, which doesn't have Java EE modules. For this option is a good idea, downgrade your Java version or wait for a Flutter update.
Ref: JDK 11: End of the road for Java EE modules
Solution 5
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
This fixed the problem on Windows for me.
Novellizator
I study at Charles university. Some of my interests are: Node.js, javascript programming, software design, machine learning and dancing ;) My homepage: http://novellizator.cz
Updated on July 08, 2022Comments
-
Novellizator almost 2 years
When installing the android sdk tools the following error is emitted:
java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
Why is this happening and how can it be fixed?
Debug output:
$ java --version java 9 Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) $ brew cask install android-sdk ==> Caveats We will install android-sdk-tools, platform-tools, and build-tools for you. You can control android sdk packages via the sdkmanager command. You may want to add to your profile: 'export ANDROID_SDK_ROOT=/usr/local/share/android-sdk' This operation may take up to 10 minutes depending on your internet connection. Please, be patient. ==> Satisfying dependencies ==> Downloading https://dl.google.com/android/repository/sdk-tools-darwin-3859397.zip Already downloaded: /Users/tomasnovella/Library/Caches/Homebrew/Cask/android-sdk--3859397,26.0.1.zip ==> Verifying checksum for Cask android-sdk ==> Installing Cask android-sdk ==> 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.SdkManagerCli.main(SdkManagerCli.java:117) ==> at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:93) ==> Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema ==> at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) ==> at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) ==> at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) ==> ... 5 more Error: Command failed to execute! ==> Failed command: /usr/local/Caskroom/android-sdk/3859397,26.0.1/tools/bin/sdkmanager tools platform-tools build-tools;26.0.1 ==> Standard Output of failed command: ==> Standard Error of failed command: 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.SdkManagerCli.main(SdkManagerCli.java:117)
-
tcardoso almost 7 yearsthx... brew cask install java is installing java9 now and that will cause this error when installing android-sdk. Had to install java8 in order to proceed
-
Kxrr over 6 years1. brew case uninstall java # uninstall java9 2. brew tap caskroom/versions 3. brew cask install java8 # install java8 4. touch ~/.android/repositories.cfg # without this file, error will occur on next step 5. brew cask install android-sdk
-
Vedvart1 over 6 yearsGot the error on windows 10, tried this, still doesn't work. Any tips?
-
Mr. Bungle over 6 years@Vedvart1 On Windows 10 x64, uninstalling JDK 9.x and installing JDK 8u161 fixed the issue for me.
-
Darragh Enright over 6 yearsGreat - this worked for me building a Flutter app in Android Studio. Thanks!
-
Julien Kronegg about 6 yearsOn Windows 10, I installed JDK 8u162 and set the
JAVA_HOME
this JDK to correct the issue. No need to uninstall JDK 9.x -
4levels about 6 yearsWorked perfectly, best solution IMHO as it doesn't force you to downgrade java
-
4levels about 6 yearsSomehow, after experimenting a lot with ao. Android Studio, this issue disappeared and the new error was
Could not find or load main class java.se.ee
- reverting the DEFAULT_JVM_OPTS fixed this and the previous issue went away.. -
Benjamin Conlan about 6 yearsAlso used this on ubuntu 16.04 (using
export
notset
) and it resolved the problem. -
flakes almost 6 yearsGenius. Thanks so much. Thought I was gonna have to change my JVM
-
pabz almost 6 yearsWorked like a charm on Windows 10 with Java 10
-
Admin almost 6 yearsThis worked for me in Ubuntu 18.04 w/ OpenJDK 10.0.2
-
Jorge Valvert over 5 yearsthanks! it solves the problem when you have installed jdk 9
-
Ambroise Rabier over 5 yearsJust read
Unity requires the 64-bit version JDK 8 (1.8).
docs.unity3d.com/Manual/android-sdksetup.html -
Tino over 5 years
$ /usr/libexec/java_home -V
givesbash: /usr/libexec/java_home: No such file or directory
.apt-file search /usr/libexec/java_home
gives exactly nothing. -
Sarah A over 5 yearsDo you have $JAVA_HOME set correctly? Run:
echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.bashrc
(or profile if you use profile) - reload:. ~/.bashrc
-
Tino over 5 yearsThere is no
/usr/libexec
either. Are you on MacOS? (I am on Ubuntu/Linux and Ubuntu/Windows) -
Sarah A over 5 yearsI am using mac. where's your Java_home?
-
Alastair Maw over 5 yearsUnfortunately that seems to have been removed entirely in Java 11.
-
Eligio Mariño over 5 yearsI prefer this answer posted below because it doesn't need to downgrade java. Just set correctly
JAVA_HOME
. -
AndyMc over 5 yearsIt works, but I get this warning: WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/F:/android_sdk/java/jaxb-ri/lib/jaxb-impl.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
-
Peter Quiring over 5 yearsYa, looks like Java is starting to warn against bad programming practice of using reflection to bypass class security, which JAXB uses (Oracle breaking their own rules) ;)
-
Subfuzion over 5 yearsWorked for me on macOS Mojave (10.14.2) with Java version "10.0.1" 2018-04-17.
-
Randy over 5 yearsCreated a new error for me on macOS Mojave (10.14.2): Error occurred during initialization of boot layer java.lang.module.FindException: Module java.se.ee not found
-
valdeci over 5 years@Randy your Java version?
-
Randy over 5 yearsjava version "11.0.1" 2018-10-16 LTS
-
Randy over 5 yearsI also tried 1.8.0_191, but am still getting: Error: Could not find or load main class java.se.ee
-
valdeci over 5 yearsThis option is not needed for the Java 8 and doesn't work for the Java 11, which doesn't have Java EE modules.
-
Déjà vu over 5 yearsWorked doing
export JAVA_OPTS = '-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
on Ubuntu 18.04 -
Oscar over 5 yearsUnfortunately, this doesn't work now. The result is: Error occurred during initialization of boot layer java.lang.module.FindException: Module java.se.ee not found
-
Sword Jason about 5 yearsThis is the best case. If you already export JAVA_OPTS. Please remove it first before you do the steps from this answer.
-
kdy about 5 yearsThis stopped working, brew cask install java8 does not work.
-
harrisjb about 5 yearsUpvoted stackoverflow.com/a/49630166/5411817 for having the correct solution for keeping jdk-11 and jdk1.8 installed without downgrading
-
caesarsol about 5 yearsthe correct command seems to be now
brew cask install homebrew/cask-versions/java8
-
guruz almost 5 years
brew cask install homebrew/cask-versions/adoptopenjdk8
seems to work -
Marwan almost 5 yearsNot working, java.lang.module.FindException: Module java.se.ee not found
-
Anubhav Dinkar over 4 yearsI have tried doing all of these steps as mentioned above, but I still get the same error message. Can anyone help me out?
-
mauriii about 4 yearsThis along with the top answer worked for me on windows 10!
-
Kaka Ruto about 4 years@AnubhavDinkar, looks like a problem with later versions after version 8. You'd have to install any java after v-8 and then install v-8(
jdk8
) -
Luiggi Mendoza almost 4 yearsWhen using Java 9+, this should be the answer from now on!
-
Raghav Joshi almost 4 yearsTHANKSSSSSSSSSSSSSS
-
Antonio Reyes almost 4 yearsWorks! I just want to add, that if you are using VS code, you have to restart the program after this change
-
Yogesh Gosavi almost 4 yearsThanks a lot for this , worked on jdk-14.0.2 , windows 10
-
MGM almost 4 yearsIn window syntax you must not use apostrophes, simply: set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee But it not works out of the box: java.lang.module.FindException: Module java.se.ee not found
-
G00fY almost 4 yearsYou should probably use the new command-line tools regardless of Java 8 oder 9+ ;)
-
valdeci over 3 years@JavaRunner, yes, like we can see at the end of the answer
-
deathangel908 over 3 yearsError: caskroom/versions was moved. Tap homebrew/cask-versions instead.
-
c z over 3 yearsshould probably mention this is linux only
-
Filip Savic over 3 years@MGM YES! I can't believe i copied the apostrophes... :D Thank you!
-
dvlcube over 3 yearsbest option if you don't want to mess with PATH variables.
-
Rohan Devaki over 3 yearsi am still having the same error, can you tell me where exactly do i need to place it
-
Smit Johnth over 3 years@RohanDevaki
c:\Users\username\AppData\Local\Android\Sdk\cmdline-tools\latest\bin\sdkmanager.bat
-
puzz over 3 yearsAnother solution is to use the JDK included in your Android studio. In my case it's:
JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home" ./sdkmanager --licenses
-
ZooMMX over 3 yearsTried the above solutions but as 2021 in a freshly installed env none worked. This is was the right answer for me.
-
Anna Billstrom over 3 yearsI had to use
brew install --cask homebrew/cask-versions/adoptopenjdk8
instead ofbrew cask install java8
-
slf over 3 yearsYou can
brew install jenv
to switch between java versions, much like nvm or virtualenv and other languages -
Pradyot over 3 yearsThanks! Curious how you figured this out.
-
G00fY about 3 years@Ashish it works for all OS. I don't know what "did not work" means, but you may check out this issue if you manually unpacked the executables: issuetracker.google.com/issues/143335476
-
Ashish about 3 yearsyou are right. I was putting it in wrong directory. It should be in $ANDROID_HOME/cmdline-tools/latest ... I was using latest stable command-line tool mentioned at the bootom.
-
lordvcs about 3 yearsUbuntu 21 woked flawlessly
-
mandrewsan about 3 yearsThis worked for me on Fedora 34 in May 2021, after a fresh install of Android Studio. Had to navigate to $ANDROID_HOME/cmdline-tools/latest/bin and accept licenses using the sdkmanager script here.
-
Raja Simon about 3 yearsyeah how you figured this out. Life saver
-
Andrew Alcock about 3 yearsI'd strongly suggest adding SDKMan to the solutions. This does a better job of managing multiple versions of Java
-
Chinky Sight about 3 yearsGetting following error when performing
flutter doctor --android-licenses
after installing theAndroid SDK Command-line Tools (latest)
:Error: Could not find or load main class Sight\AppData\Local\Android\Sdk\cmdline-tools\latest\bin\\.. Caused by: java.lang.ClassNotFoundException: Sight\AppData\Local\Android\Sdk\cmdline-tools\latest\bin\\//
-
Jean-Paul about 3 yearsFinally, a solution that works. I cannot thank you enough for posting this!
-
Harsh Kumar about 3 yearsThanks a lot, this saved my day. I was having a nightmare before this.
-
Omar Shabab about 3 years
brew install homebrew/cask-versions/adoptopenjdk8
worked for me. -
Sam Watkins about 3 yearsThis answer is obsolete, see below for up-to-date answers, e.g. this one: stackoverflow.com/a/64389804/218294
-
Dasun wijesundara about 3 yearsWork for me on Ubuntu 20.04 LTS..Thanks @Sam_Watkins
-
ANDYNVT about 3 yearsFor macOS Big Sur users, use:
brew install --cask ...
-
nafsaka about 3 yearsNow (6 Juni 2021), android studio no longer use java8 but java11. This should be the correct answer, rather downgrade the version of java.
-
Bhikkhu Subhuti about 3 yearsI'll have to remember this one. Getting the license tool to work was crazy for JAVA_HOME and this little tick mark and 5 minutes let me build my project. Nice screenshots too.
-
Suryakant Bharti about 3 yearsThis should be marked correct answer. Downgrading Java is not the correct approach, that is highly regressive!
-
devsin almost 3 yearsit is not about the Java version guys. it's about the
command-line tools
. I passed this error Java 16 after I install command-line tools. Also you can find the correct answer page two in this question.Android Studio -> SDK Manager -> SDK Tools -> Android SDK Command-line Tools -> Install
-
London Tran almost 3 yearsWorked for me on Windows 10! Thank you!
-
abbas almost 3 yearsWorked on macOS 10.15.7 and Java 11.0.4
-
Priyanka almost 3 yearsthis worked for me on M1 chip macOS big Sur 11.5.1
-
Eloy B. almost 3 yearsSolved my issue with Flutter setup not being able to accept licenses on M1 Big Sur
-
Trect almost 3 yearsNow, there is no option called "Preferences" on Android studio. "System Settings" are now available in File
-
Trect almost 3 yearsApparently, java.se.ee does not exist anymore
-
DaveFX almost 3 yearsThis shouldn't be the accepted solution any longer, but the one from EdYuTo!
-
nathan almost 3 yearsPreferences is now under File -> Settings... (Ctrl + Alt + S)
-
FutureCap almost 3 yearsThis answer helped me fixing it (on Windows 10). But I used "sdkmanager --licenses" in the folder "...\cmdline-tools\latest\bin" to accept all missing licenses.
-
Raphael Pinel almost 3 yearsOn a Mac, Click on top left on 'Android Studio', then Preferences, or
Cmd ,
-
Tushar Sheth almost 3 yearsThis solution worked for me. After struggling for a whole day, it saved me. Thanks.
-
AmerllicA over 2 yearsPretty answer, thanks. it makes my day
-
Aashish Kumar over 2 yearsThanks it worked for me
-
iRestMyCaseYourHonor over 2 yearsworks like a charm
-
Mauricio Aviles over 2 yearsThis should be marked as the correct answer.
-
Syed Amir Ali over 2 yearsthanks it worked for my m1
-
Gili Yaniv over 2 yearsI'm still getting errors on mac You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=31'. java 17.0.2 Any idea why?
-
hansaplast over 2 yearsI tried a lot of things, this was the missing link for me on OSX Big Sur
-
MagicMike over 2 years@Pradyot In the event you're running into build issues where your environment might be the culprit, it's a good idea to always run
flutter doctor -v
-
Dragan Marjanović over 2 yearson my macOS in addition to what's explained I had also to move
$ANDROID_HOME/tools/bin
inPATH
to after$ANDROID_HOME/cmdline-tools/latest/bin
since there are failing sdkmanager/avdmanager binaries in there -
JCraine about 2 yearsThankyou!! The images really helped. (2022)
-
IgorGanapolsky about 2 yearsWhat if we want to run
avdmanager
from commandline? -
Priyansh jain about 2 years@IgorGanapolsky . I only use physical device but here is what I have found from the official documentation: developer.android.com/studio/run/emulator-commandline