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

404,874

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.

  1. brew cask uninstall java # uninstall java9
  2. brew tap homebrew/cask-versions
  3. brew cask install java8 # install java8
  4. touch ~/.android/repositories.cfg # without this file, error will occur on next step
  5. 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

Android SDK path on Android Studio

Command-line Tools

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 image description here

enter image description here enter image description here

  • restart the command line tool enter image description here

  • enter the command flutter doctor

  • enter the command flutter doctor --android-licenses

  • and accept all the licenses by typing y.

enter image description here

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.

Source 1, source 2

Share:
404,874
Novellizator
Author by

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, 2022

Comments

  • Novellizator
    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
    tcardoso almost 7 years
    thx... 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
    Kxrr over 6 years
    1. 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
    Vedvart1 over 6 years
    Got the error on windows 10, tried this, still doesn't work. Any tips?
  • Mr. Bungle
    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
    Darragh Enright over 6 years
    Great - this worked for me building a Flutter app in Android Studio. Thanks!
  • Julien Kronegg
    Julien Kronegg about 6 years
    On 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
    4levels about 6 years
    Worked perfectly, best solution IMHO as it doesn't force you to downgrade java
  • 4levels
    4levels about 6 years
    Somehow, 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
    Benjamin Conlan about 6 years
    Also used this on ubuntu 16.04 (using export not set) and it resolved the problem.
  • flakes
    flakes almost 6 years
    Genius. Thanks so much. Thought I was gonna have to change my JVM
  • pabz
    pabz almost 6 years
    Worked like a charm on Windows 10 with Java 10
  • Admin
    Admin almost 6 years
    This worked for me in Ubuntu 18.04 w/ OpenJDK 10.0.2
  • Jorge Valvert
    Jorge Valvert over 5 years
    thanks! it solves the problem when you have installed jdk 9
  • Ambroise Rabier
    Ambroise Rabier over 5 years
    Just read Unity requires the 64-bit version JDK 8 (1.8). docs.unity3d.com/Manual/android-sdksetup.html
  • Tino
    Tino over 5 years
    $ /usr/libexec/java_home -V gives bash: /usr/libexec/java_home: No such file or directory. apt-file search /usr/libexec/java_home gives exactly nothing.
  • Sarah A
    Sarah A over 5 years
    Do 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
    Tino over 5 years
    There is no /usr/libexec either. Are you on MacOS? (I am on Ubuntu/Linux and Ubuntu/Windows)
  • Sarah A
    Sarah A over 5 years
    I am using mac. where's your Java_home?
  • Alastair Maw
    Alastair Maw over 5 years
    Unfortunately that seems to have been removed entirely in Java 11.
  • Eligio Mariño
    Eligio Mariño over 5 years
    I prefer this answer posted below because it doesn't need to downgrade java. Just set correctly JAVA_HOME.
  • AndyMc
    AndyMc over 5 years
    It 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[],in‌​t,int)
  • Peter Quiring
    Peter Quiring over 5 years
    Ya, 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
    Subfuzion over 5 years
    Worked for me on macOS Mojave (10.14.2) with Java version "10.0.1" 2018-04-17.
  • Randy
    Randy over 5 years
    Created 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
    valdeci over 5 years
    @Randy your Java version?
  • Randy
    Randy over 5 years
    java version "11.0.1" 2018-10-16 LTS
  • Randy
    Randy over 5 years
    I also tried 1.8.0_191, but am still getting: Error: Could not find or load main class java.se.ee
  • valdeci
    valdeci over 5 years
    This 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
    Déjà vu over 5 years
    Worked doing export JAVA_OPTS = '-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee' on Ubuntu 18.04
  • Oscar
    Oscar over 5 years
    Unfortunately, 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
    Sword Jason about 5 years
    This is the best case. If you already export JAVA_OPTS. Please remove it first before you do the steps from this answer.
  • kdy
    kdy about 5 years
    This stopped working, brew cask install java8 does not work.
  • harrisjb
    harrisjb about 5 years
    Upvoted stackoverflow.com/a/49630166/5411817 for having the correct solution for keeping jdk-11 and jdk1.8 installed without downgrading
  • caesarsol
    caesarsol about 5 years
    the correct command seems to be now brew cask install homebrew/cask-versions/java8
  • guruz
    guruz almost 5 years
    brew cask install homebrew/cask-versions/adoptopenjdk8 seems to work
  • Marwan
    Marwan almost 5 years
    Not working, java.lang.module.FindException: Module java.se.ee not found
  • Anubhav Dinkar
    Anubhav Dinkar over 4 years
    I have tried doing all of these steps as mentioned above, but I still get the same error message. Can anyone help me out?
  • mauriii
    mauriii about 4 years
    This along with the top answer worked for me on windows 10!
  • Kaka Ruto
    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
    Luiggi Mendoza almost 4 years
    When using Java 9+, this should be the answer from now on!
  • Raghav Joshi
    Raghav Joshi almost 4 years
    THANKSSSSSSSSSSSSSS
  • Antonio Reyes
    Antonio Reyes almost 4 years
    Works! I just want to add, that if you are using VS code, you have to restart the program after this change
  • Yogesh Gosavi
    Yogesh Gosavi almost 4 years
    Thanks a lot for this , worked on jdk-14.0.2 , windows 10
  • MGM
    MGM almost 4 years
    In 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
    G00fY almost 4 years
    You should probably use the new command-line tools regardless of Java 8 oder 9+ ;)
  • valdeci
    valdeci over 3 years
    @JavaRunner, yes, like we can see at the end of the answer
  • deathangel908
    deathangel908 over 3 years
    Error: caskroom/versions was moved. Tap homebrew/cask-versions instead.
  • c z
    c z over 3 years
    should probably mention this is linux only
  • Filip Savic
    Filip Savic over 3 years
    @MGM YES! I can't believe i copied the apostrophes... :D Thank you!
  • dvlcube
    dvlcube over 3 years
    best option if you don't want to mess with PATH variables.
  • Rohan Devaki
    Rohan Devaki over 3 years
    i am still having the same error, can you tell me where exactly do i need to place it
  • Smit Johnth
    Smit Johnth over 3 years
    @RohanDevaki c:\Users\username\AppData\Local\Android\Sdk\cmdline-tools\la‌​test\bin\sdkmanager.‌​bat
  • puzz
    puzz over 3 years
    Another 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
    ZooMMX over 3 years
    Tried the above solutions but as 2021 in a freshly installed env none worked. This is was the right answer for me.
  • Anna Billstrom
    Anna Billstrom over 3 years
    I had to use brew install --cask homebrew/cask-versions/adoptopenjdk8 instead of brew cask install java8
  • slf
    slf over 3 years
    You can brew install jenv to switch between java versions, much like nvm or virtualenv and other languages
  • Pradyot
    Pradyot over 3 years
    Thanks! Curious how you figured this out.
  • G00fY
    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
    Ashish about 3 years
    you 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
    lordvcs about 3 years
    Ubuntu 21 woked flawlessly
  • mandrewsan
    mandrewsan about 3 years
    This 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
    Raja Simon about 3 years
    yeah how you figured this out. Life saver
  • Andrew Alcock
    Andrew Alcock about 3 years
    I'd strongly suggest adding SDKMan to the solutions. This does a better job of managing multiple versions of Java
  • Chinky Sight
    Chinky Sight about 3 years
    Getting following error when performing flutter doctor --android-licenses after installing the Android 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
    Jean-Paul about 3 years
    Finally, a solution that works. I cannot thank you enough for posting this!
  • Harsh Kumar
    Harsh Kumar about 3 years
    Thanks a lot, this saved my day. I was having a nightmare before this.
  • Omar Shabab
    Omar Shabab about 3 years
    brew install homebrew/cask-versions/adoptopenjdk8 worked for me.
  • Sam Watkins
    Sam Watkins about 3 years
    This answer is obsolete, see below for up-to-date answers, e.g. this one: stackoverflow.com/a/64389804/218294
  • Dasun wijesundara
    Dasun wijesundara about 3 years
    Work for me on Ubuntu 20.04 LTS..Thanks @Sam_Watkins
  • ANDYNVT
    ANDYNVT about 3 years
    For macOS Big Sur users, use: brew install --cask ...
  • nafsaka
    nafsaka about 3 years
    Now (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
    Bhikkhu Subhuti about 3 years
    I'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
    Suryakant Bharti about 3 years
    This should be marked correct answer. Downgrading Java is not the correct approach, that is highly regressive!
  • devsin
    devsin almost 3 years
    it 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
    London Tran almost 3 years
    Worked for me on Windows 10! Thank you!
  • abbas
    abbas almost 3 years
    Worked on macOS 10.15.7 and Java 11.0.4
  • Priyanka
    Priyanka almost 3 years
    this worked for me on M1 chip macOS big Sur 11.5.1
  • Eloy B.
    Eloy B. almost 3 years
    Solved my issue with Flutter setup not being able to accept licenses on M1 Big Sur
  • Trect
    Trect almost 3 years
    Now, there is no option called "Preferences" on Android studio. "System Settings" are now available in File
  • Trect
    Trect almost 3 years
    Apparently, java.se.ee does not exist anymore
  • DaveFX
    DaveFX almost 3 years
    This shouldn't be the accepted solution any longer, but the one from EdYuTo!
  • nathan
    nathan almost 3 years
    Preferences is now under File -> Settings... (Ctrl + Alt + S)
  • FutureCap
    FutureCap almost 3 years
    This 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
    Raphael Pinel almost 3 years
    On a Mac, Click on top left on 'Android Studio', then Preferences, or Cmd ,
  • Tushar Sheth
    Tushar Sheth almost 3 years
    This solution worked for me. After struggling for a whole day, it saved me. Thanks.
  • AmerllicA
    AmerllicA over 2 years
    Pretty answer, thanks. it makes my day
  • Aashish Kumar
    Aashish Kumar over 2 years
    Thanks it worked for me
  • iRestMyCaseYourHonor
    iRestMyCaseYourHonor over 2 years
    works like a charm
  • Mauricio Aviles
    Mauricio Aviles over 2 years
    This should be marked as the correct answer.
  • Syed Amir Ali
    Syed Amir Ali over 2 years
    thanks it worked for my m1
  • Gili Yaniv
    Gili Yaniv over 2 years
    I'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
    hansaplast over 2 years
    I tried a lot of things, this was the missing link for me on OSX Big Sur
  • MagicMike
    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ć
    Dragan Marjanović over 2 years
    on my macOS in addition to what's explained I had also to move $ANDROID_HOME/tools/bin in PATH to after $ANDROID_HOME/cmdline-tools/latest/bin since there are failing sdkmanager/avdmanager binaries in there
  • JCraine
    JCraine about 2 years
    Thankyou!! The images really helped. (2022)
  • IgorGanapolsky
    IgorGanapolsky about 2 years
    What if we want to run avdmanager from commandline?
  • Priyansh jain
    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