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

40

543

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)
Genteelism answered 25/9, 2017 at 10:16 Comment(6)
Actually this question asks a legit problem with installing the android sdk when having java9Ergonomics
I has this problem, and I copy/pasted the first line of my error message into google, and this question was the first hit that came up. Not only that, one of the answers below solved it. This should totally not be closed: no matter what the rules of questions are, this question demonstrably fulfills the whole purpose of the site.Lunetta
Delete anything older than Java 8 from /Library/Java/JavaVirtualMachinesExpertise
The problem occurs with Java 8 and Java 11 on Ubuntu 18.04 using packages openjdk-8-jdk and openjdk-11-jdk. Does anyone know what to install for javax/xml/bind/annotation/XmlSchema, or how to avoid javax/xml/bind/annotation/XmlSchema in the NDK?Norbert
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 -> InstallChamonix
@ssss, thanks. that's the actual cause "command-line tools".Specter
T
187

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.

  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
Thinker answered 25/9, 2017 at 12:18 Comment(22)
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 proceedGardy
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-sdkTransposition
Got the error on windows 10, tried this, still doesn't work. Any tips?Rentroll
@Rentroll On Windows 10 x64, uninstalling JDK 9.x and installing JDK 8u161 fixed the issue for me.Deathful
Great - this worked for me building a Flutter app in Android Studio. Thanks!Nostoc
On Windows 10, I installed JDK 8u162 and set the JAVA_HOME this JDK to correct the issue. No need to uninstall JDK 9.xTennilletennis
Just read Unity requires the 64-bit version JDK 8 (1.8). docs.unity3d.com/Manual/android-sdksetup.htmlInhume
I prefer this answer posted below because it doesn't need to downgrade java. Just set correctly JAVA_HOME.Volny
This stopped working, brew cask install java8 does not work.Fencing
the correct command seems to be now brew cask install homebrew/cask-versions/java8Firmament
brew cask install homebrew/cask-versions/adoptopenjdk8 seems to workSarto
I have tried doing all of these steps as mentioned above, but I still get the same error message. Can anyone help me out?Statesmanship
@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)Driskell
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 --licensesEpoxy
I had to use brew install --cask homebrew/cask-versions/adoptopenjdk8 instead of brew cask install java8Gad
You can brew install jenv to switch between java versions, much like nvm or virtualenv and other languagesCalyces
I'd strongly suggest adding SDKMan to the solutions. This does a better job of managing multiple versions of JavaOutsell
brew install homebrew/cask-versions/adoptopenjdk8 worked for me.Blanket
This answer is obsolete, see below for up-to-date answers, e.g. this one: https://mcmap.net/q/22039/-failed-to-install-android-sdk-quot-java-lang-noclassdeffounderror-javax-xml-bind-annotation-xmlschema-quotEvetteevey
For macOS Big Sur users, use: brew install --cask ...Geology
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 -> InstallChamonix
This shouldn't be the accepted solution any longer, but the one from EdYuTo!Rem
S
587

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

NOTE: For Android Studio Android Studio Giraffe | 2022.3.1 Patch 1, find these setting under File > Settings and, in the left panel, Languages & Frameworks > Android SDK and finally select the SDK Tools.

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
Socialist answered 16/10, 2020 at 13:8 Comment(19)
Tried the above solutions but as 2021 in a freshly installed env none worked. This is was the right answer for me.Photomap
Ubuntu 21 woked flawlesslyTamikatamiko
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\\//Darrondarrow
Work for me on Ubuntu 20.04 LTS..Thanks @Sam_WatkinsTransom
This should be marked correct answer. Downgrading Java is not the correct approach, that is highly regressive!Kayser
Worked on macOS 10.15.7 and Java 11.0.4Profound
this worked for me on M1 chip macOS big Sur 11.5.1Vanhomrigh
Solved my issue with Flutter setup not being able to accept licenses on M1 Big SurChild
Now, there is no option called "Preferences" on Android studio. "System Settings" are now available in FileBrickbat
Preferences is now under File -> Settings... (Ctrl + Alt + S)Bamako
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.Kyles
On a Mac, Click on top left on 'Android Studio', then Preferences, or Cmd ,Dongola
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?Feder
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 thereNoggin
still facing this issue in the env. Cordova11 android10Labyrinth
The main point is use tools from $ANDROID_HOME/cmdline-tools/latest/bin instead of $ANDROID_HOME/tools/bin.Visa
This did not work for me on linux. I needed to navigate into the tools/bin folder and run sdkmanager from there.Salzman
As for android studio electric eel, the android sdk is available through system settings and not preferencesJoellejoellen
NOTE that this error may also suddenly pop-up after you, for some reason, changed your adb key! (~/.android/adbkey and ~/.android/adbkey.pub) In case you have access to your old adb key + pub file (like I had) you may just re-instate the old key and the error will go away.Altheta
T
187

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.

  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
Thinker answered 25/9, 2017 at 12:18 Comment(22)
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 proceedGardy
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-sdkTransposition
Got the error on windows 10, tried this, still doesn't work. Any tips?Rentroll
@Rentroll On Windows 10 x64, uninstalling JDK 9.x and installing JDK 8u161 fixed the issue for me.Deathful
Great - this worked for me building a Flutter app in Android Studio. Thanks!Nostoc
On Windows 10, I installed JDK 8u162 and set the JAVA_HOME this JDK to correct the issue. No need to uninstall JDK 9.xTennilletennis
Just read Unity requires the 64-bit version JDK 8 (1.8). docs.unity3d.com/Manual/android-sdksetup.htmlInhume
I prefer this answer posted below because it doesn't need to downgrade java. Just set correctly JAVA_HOME.Volny
This stopped working, brew cask install java8 does not work.Fencing
the correct command seems to be now brew cask install homebrew/cask-versions/java8Firmament
brew cask install homebrew/cask-versions/adoptopenjdk8 seems to workSarto
I have tried doing all of these steps as mentioned above, but I still get the same error message. Can anyone help me out?Statesmanship
@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)Driskell
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 --licensesEpoxy
I had to use brew install --cask homebrew/cask-versions/adoptopenjdk8 instead of brew cask install java8Gad
You can brew install jenv to switch between java versions, much like nvm or virtualenv and other languagesCalyces
I'd strongly suggest adding SDKMan to the solutions. This does a better job of managing multiple versions of JavaOutsell
brew install homebrew/cask-versions/adoptopenjdk8 worked for me.Blanket
This answer is obsolete, see below for up-to-date answers, e.g. this one: https://mcmap.net/q/22039/-failed-to-install-android-sdk-quot-java-lang-noclassdeffounderror-javax-xml-bind-annotation-xmlschema-quotEvetteevey
For macOS Big Sur users, use: brew install --cask ...Geology
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 -> InstallChamonix
This shouldn't be the accepted solution any longer, but the one from EdYuTo!Rem
B
132
  • 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

Banditry answered 28/12, 2020 at 12:11 Comment(5)
Thanks! Curious how you figured this out.Ingredient
Finally, a solution that works. I cannot thank you enough for posting this!Wilhelm
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.Kirin
Worked for me on Windows 10! Thank you!Kinematics
@Ingredient 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 -vKashgar
T
98

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

Talie answered 2/8, 2018 at 2:55 Comment(12)
This worked for me in Ubuntu 18.04 w/ OpenJDK 10.0.2Bridesmaid
Worked for me on macOS Mojave (10.14.2) with Java version "10.0.1" 2018-04-17.Witch
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 foundAnnabelannabela
@Annabelannabela your Java version?Talie
java version "11.0.1" 2018-10-16 LTSAnnabelannabela
I also tried 1.8.0_191, but am still getting: Error: Could not find or load main class java.se.eeAnnabelannabela
This option is not needed for the Java 8 and doesn't work for the Java 11, which doesn't have Java EE modules.Talie
Not working, java.lang.module.FindException: Module java.se.ee not foundErlene
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 foundMercurial
@JavaRunner, yes, like we can see at the end of the answerTalie
@Mercurial YES! I can't believe i copied the apostrophes... :D Thank you!Analemma
Apparently, java.se.ee does not exist anymoreBrickbat
P
68
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee

This fixed the problem on Windows for me.

Source 1, source 2

Pyroxylin answered 30/5, 2018 at 12:35 Comment(6)
Also used this on ubuntu 16.04 (using export not set) and it resolved the problem.Aeolic
Genius. Thanks so much. Thought I was gonna have to change my JVMRafael
Worked like a charm on Windows 10 with Java 10Forzando
Unfortunately that seems to have been removed entirely in Java 11.Biff
Worked doing export JAVA_OPTS = '-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee' on Ubuntu 18.04Sunderland
Thanks a lot for this , worked on jdk-14.0.2 , windows 10Foretopsail
R
61

Update 2019-10:

As stated in the issue tracker, Google has been working on a new Android SDK Command-line Tools release that runs on current JVMs (9, 10, 11+) and does not depend on deprecated JAXB EE modules!

You can download and use the new Android SDK Command-line Tools inside Android Studio or by manually downloading them from the Google servers:

For the latest versions check the URLs inside the repository.xml.

If you manually unpack the command line tools, take care of placing them in a subfolder inside your $ANDROID_HOME (e.g. $ANDROID_HOME/cmdline-tools/...).

Update 2021-03:

The latest stable command-line tools are available at Googles Downloads-Website. These tools are newer than those linked above.

Riegel answered 31/10, 2019 at 23:23 Comment(8)
When using Java 9+, this should be the answer from now on!Britney
You should probably use the new command-line tools regardless of Java 8 oder 9+ ;)Riegel
i am still having the same error, can you tell me where exactly do i need to place itBanditry
@RohanDevaki c:\Users\username\AppData\Local\Android\Sdk\cmdline-tools\latest\bin\sdkmanager.batTool
@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/143335476Riegel
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.Reedreedbird
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.Therefrom
Now (6 Juni 2021), android studio no longer use java8 but java11. This should be the correct answer, rather downgrade the version of java.Symmetrize
S
36

If you're on Mac OS, and you don't want to change your Java version (I don't), you can temporarily change the version in your shell:

First run

/usr/libexec/java_home -V

Then pick a major version if you have it installed, otherwise install it first:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Now you can run sdkmanager.

Sympathetic answered 12/10, 2018 at 23:10 Comment(4)
$ /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.Chrystal
Do you have $JAVA_HOME set correctly? Run: echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.bashrc (or profile if you use profile) - reload: . ~/.bashrcSympathetic
There is no /usr/libexec either. Are you on MacOS? (I am on Ubuntu/Linux and Ubuntu/Windows)Chrystal
I am using mac. where's your Java_home?Sympathetic
R
28

When using Linux, an easy option is installation of JDK version 8 then selecting it as the default using:

sudo update-alternatives --config java
Recalesce answered 12/3, 2019 at 11:57 Comment(1)
should probably mention this is linux onlyBosquet
N
24

On Mac/Linux use the following command:

export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

Works for both JDK 9 and 10, without patching any script (sdkmanager, avdmanager).

For Java 11 see: https://mcmap.net/q/22039/-failed-to-install-android-sdk-quot-java-lang-noclassdeffounderror-javax-xml-bind-annotation-xmlschema-quot

Nutbrown answered 23/7, 2018 at 8:35 Comment(1)
thanks! it solves the problem when you have installed jdk 9Widthwise
P
21

You need to add the following to your Profile (Works on MacOS):

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

No need to patch anything.

Pinkney answered 5/12, 2018 at 19:58 Comment(0)
E
21

While building the flutter application an error occurred saying android sdk licenses not accepted. So, while accepting the license this error occurred.

Reason for this error in my case was I haven't installed sdkmanager command line tools which is required to accept the license.

So, to install command line tools easiest way is:

  1. Open android studio.
  2. Open SDK Manager (refer image below): enter image description here
  1. Select SDK tools inside it in bar.
  2. Tick the option Android SDK Command-line Tools (latest)
  3. Apply it.
  4. Run flutter doctor -android-licenses if using flutter or you can continue with the process where the error occurred.
Eisler answered 5/12, 2021 at 10:49 Comment(2)
What if we want to run avdmanager from commandline?Gyral
@Gyral . I only use physical device but here is what I have found from the official documentation: developer.android.com/studio/run/emulator-commandlineEisler
D
15

I found two answers that worked for me, without having to uninstall JDK 10 (or 9), which I need for create-react-app. Both JDK 9 and 10 are incompatible with android-sdk !


Siu Ching Pong -Asuka Kenji- suggests modifying the sdkmanager script, replacing this line:

DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME"'  

with:

DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

Note that this mod will be overwritten when updating sdkmanager.
Check out his post, and the one he links to, for more details.
This solution was also one of the solutions mentioned in this github issues thread.


German's post indicates the source of the conflict, and presents fix that will not not be overwritten by updates.
He suggests renaming /Library/Java/JavaVirtualMachines/Info.plist as a means of obscuring it from the script that looks for the highest version of Java that resides on your system. In this way, JDK 8 is returned as the default.
Referring to JDK 10 explicitly, or by setting it to $JAVA_HOME, you can use JDK 10 , instead of the default, whenever needed.
Details are in his post.

Descender answered 11/5, 2018 at 4:55 Comment(4)
Worked perfectly, best solution IMHO as it doesn't force you to downgrade javaEllinger
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..Ellinger
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 foundLarrigan
Upvoted https://mcmap.net/q/22041/-how-to-configure-unity-2017-4-to-target-android-and-avoid-build-failures-on-osx for having the correct solution for keeping jdk-11 and jdk1.8 installed without downgradingSteerageway
S
13

Strangely Java9 is not compatible with android-sdk

$ avdmanager
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.AvdManagerCli.run(AvdManagerCli.java:213)
    at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
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

Combined all commands into one for easy reference:

$ sudo rm -fr /Library/Java/JavaVirtualMachines/jdk-9*.jdk/
$ sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
$ sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane

$ /usr/libexec/java_home -V
Unable to find any JVMs matching version "(null)".
Matching Java Virtual Machines (0):
Default Java Virtual Machines (0):
No Java runtime present, try --request to install

$ brew tap caskroom/versions
$ brew cask install java8
$ touch ~/.android/repositories.cfg
$ brew cask install android-sdk
$ echo 'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"' >> ~/.bash_profile
$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
$ avdmanager

Usage:
      avdmanager [global options] [action] [action options]
      Global options:
  -s --silent     : Silent mode, shows errors only.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -h --help       : Help on a specific command.

Valid actions are composed of a verb and an optional direct object:
-   list              : Lists existing targets or virtual devices.
-   list avd          : Lists existing Android Virtual Devices.
-   list target       : Lists existing targets.
-   list device       : Lists existing devices.
- create avd          : Creates a new Android Virtual Device.
-   move avd          : Moves or renames an Android Virtual Device.
- delete avd          : Deletes an Android Virtual Device.
Socrates answered 11/3, 2018 at 8:46 Comment(1)
Error: caskroom/versions was moved. Tap homebrew/cask-versions instead.Bainbridge
H
12

I faced the same problem. Though I am a little bit backdated developer (Still using windows to develop :P)

To solve this issue on windows :

STEP 1: Install jdk 8 if it wasn't installed (jdk 9 or 11 doesn't work but you may have them installed for using in other dev uses).

Very simple using Chocolatey:

choco install jdk8

(If installed using Chocolatey, skip steps 2 and 3)

STEP 2: Go to the Environment variables settings and set JAVA_HOME TO jdk 8's installation directory.

JAVA_HOME

STEP 3: Go to path variable and add bin directory of jdk 8 and move it to top.

Path_varriable

STEP 4: Close any open terminal sessions and restart a new session

OPTIONAL STEP 5: Depending on your objective in the terminal run (may need to add sdkmanager to path or just navigate to the directory):

sdkmanager --update

That's all! :O Enjoy fluttering! :D

Heflin answered 7/12, 2019 at 14:18 Comment(4)
This along with the top answer worked for me on windows 10!Gonzalogoo
THANKSSSSSSSSSSSSSSClot
Works! I just want to add, that if you are using VS code, you have to restart the program after this changePrecise
This worked for me on windows 10. Thanks.Relucent
U
9

I ran into same issue when running:

$ /Users/<username>/Library/Android/sdk/tools/bin/sdkmanager "platforms;android-28" "build-tools;28.0.3"_

I solved it as

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home    

$ ls /Library/Java/JavaVirtualMachines/

jdk-11.0.1.jdk      
jdk1.8.0_202.jdk

Change Java to use 1.8

$ export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home'

Then the same command runs fine

$ /Users/<username>/Library/Android/sdk/tools/bin/sdkmanager "platforms;android-28" "build-tools;28.0.3"
Uniseptate answered 21/2, 2019 at 7:7 Comment(1)
This is the best case. If you already export JAVA_OPTS. Please remove it first before you do the steps from this answer.Kaczmarek
D
8

Since Java 11 has removed JavaEE you'll need to download some jars and add to the classpath:

JAXB: https://javaee.github.io/jaxb-v2/

JAF: https://www.oracle.com/technetwork/articles/java/index-135046.html

Then edit sdkmanager.bat so that set CLASSPATH=... ends with ;%CLASSPATH%

Set CLASSPATH to include JAXB and JAF:

set CLASSPATH=jaxb-core.jar;jaxb-impl.jar;jaxb-api.jar;activation.jar

Then sdkmanager.bat will work.

Dyandyana answered 16/11, 2018 at 15:30 Comment(2)
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[],int,int)Cryptograph
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) ;)Dyandyana
K
5

In my case, I need both JDK 8 (trying to use the AVD and SDK manager in Qt under ubuntu) and 11 for different tools. Removing version 11 is not an option.

The 'JAVA_OPTS' solutions did not do anything. I don't really like the export JAVA_HOME, as it might force you do launch whatever tool calls these utils from the same shell (like Qt), or force you to make this permanent, which is not convenient.

So for me the solution is quite simple. Add something like this in the second line of ~/Android/tools/bin/sdkmanager and ~/Android/tools/bin/avdmanager:

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

(or whatever the path is to your rev 8 jdk).

With this, these command line tools work in a stand alone mode, they work also when called by other tools such as Qt, and jdk 11 is still the system default for others. No need to mix libs etc...

The only downside is that any update to these command line tools will erase these modifications, which you will have to put back in.

Khelat answered 19/6, 2020 at 15:21 Comment(1)
best option if you don't want to mess with PATH variables.Donner
B
5

In my case, I have Java 14 and need Java 8.

I'm in a Arch Linux and has installed jdk8-openjdk jre8-openjdk https://www.archlinux.org/packages/extra/x86_64/java8-openjdk/

For Debian users https://wiki.debian.org/Java, or Fedora https://docs.fedoraproject.org/en-US/quick-docs/installing-java/.

Install Java 8 (or desired version, in this case jdk8-openjdk jre8-openjdk) using your package manager before doing the following steps.


1. Figuring out where is my Java:

# which java
/usr/bin/java

2. Checking java files:

I can see all java files here are links to /usr/lib/jvm/default[something]. This means that the java command is linked to some specific version of java executable.

# ls -l /usr/bin/java*
lrwxrwxrwx 1 root root 37 May 16 06:30 /usr/bin/java -> /usr/lib/jvm/default-runtime/bin/java
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javac -> /usr/lib/jvm/default/bin/javac
lrwxrwxrwx 1 root root 32 May 16 06:30 /usr/bin/javadoc -> /usr/lib/jvm/default/bin/javadoc
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javah -> /usr/lib/jvm/default/bin/javah
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javap -> /usr/lib/jvm/default/bin/javap

3. Checking the default and default-runtime

Here I could see the default version was linked to 14 (unique installed version).

# cd /usr/lib/jvm
# ls -l
lrwxrwxrwx 1 root root   14 Aug  8 20:44 default -> java-14-openjdk
lrwxrwxrwx 1 root root   14 Aug  8 20:44 default-runtime -> java-14-openjdk
drwxr-xr-x 7 root root 4096 Jul 19 22:38 java-14-openjdk
drwxr-xr-x 6 root root 4096 Aug  8 20:42 java-8-openjdk

4. Switching the default version

First, remove the existing default and default-runtime which linked to java-14 version.

# rm default default-runtime

Then, create new links to the desired version (in this case, java-8).

# ln -s java-8-openjdk default
# ln -s java-8-openjdk default-runtime

The strategy is to make links to the desired version of software (java8 in this case) using ln -s above. Then, this links are linked to the binaries inside the java bin directory (without changing the $PATH environment variable!)


Or you might be wanted to change the Java version using archlinux-java command instead with more safely approach: https://wiki.archlinux.org/index.php/Java

Belindabelisarius answered 9/8, 2020 at 0:10 Comment(0)
H
5

As of the latest version of the Android command-line tools (2.1 as of this writing), it is no longer necessary to patch sdkmanager nor to downgrade to an ancient version of Java.

Simply update your SDK packages and switch your command-line tools to the latest release, which will track new versions as they come:

sdkmanager --update
sdkmanager 'cmdline-tools;latest'
sdkmanager --uninstall 'cmdline-tools;1.0'

You may need to provide the full path to sdkmanager if it's not on your PATH, and you may need to adjust your PATH afterwards if it was referring to the 1.0 tools explicitly.

Hanse answered 31/8, 2020 at 6:28 Comment(0)
S
4

TLDR; Try setting JAVA_HOME worked fine for me on OSX

export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

To install the JDKs 8 ( LTS ) from AdoptOpenJDK:

# brew tap adoptopenjdk/openjdk

brew cask install adoptopenjdk/openjdk/adoptopenjdk8
Solfatara answered 22/9, 2020 at 18:55 Comment(1)
I tried a lot of things, this was the missing link for me on OSX Big SurShirleeshirleen
V
4

For Windows users looking for solution

Option 1 Install the cmdline-tools from within the Android Studio SDK manager

enter image description here


Option 2 Download from this link https://developer.android.com/studio#cmdline-tools

Then follow this tutorial below on how to set it up https://www.youtube.com/watch?v=wvi03sOBKWQ


Next copy the path to where the cmdline-tools was installed towards the bin folder

Using Android Studio SDK Manager
The cmdline-tools is installed under the Android SDK Location
Example:
C:\Users\%username%\AppData\Local\Android\Sdk\cmdline-tools\latest\bin


Then paste the path in to the Environment Variable Path

Control Panel> Set the View By to Large Icons>System>Under 'Related Settings' on the right side choose Advanced System Settings>Environment Variables

From here you add the path under System variables enter image description here

Make sure that the cmdline-tools path is above the tools path (highlighted in the picture in red box) if they exist.

Select the Path>Edit>Select the cmdline-tools path (highlighted in blue) >Move Up

Vassalage answered 11/9, 2022 at 22:16 Comment(3)
I think the issue here is that it conflicts with the existing sdk tools files so by moving the cmdline-tools path up solves which path files to access first and i hope others can replicate in linux environment ^_^ "avdmanager works" no need to downgradeVassalage
For MacOS user, option 1 is the simplest solution. 👍Fons
Hi @Vassalage i did what you said but now when i am running i am getting this error "Failed to find 'ANDROID_HOME' environment variable. Try setting it manually. Detected 'avdmanager' command at C:\Users\aksha\AppData\Local\Android\Sdk\cmdline-tools\latest\bin but no 'tools\bin' directory found near. Try reinstall Android SDK or update your PATH to include valid path to SDK\tools\bin directory. "Allophane
E
3

This question has numerous answers, and they're all different due to users installing different toolchains and using different Java versions.

The recommended way of using Android development toolchain, or at least the one that I suggest to use, is to follow what's stated in Android Studio documentation:

You should always keep your Build Tools component updated by downloading the latest version using the Android SDK Manager.

Android studio allows you to easily manage installed SDKs & build tools, yes, it requires some space on your hard drive, but it will save you some time. Once you get familiar with how it works, then you can think of installing command-line tools only.

If there's no particular reason of using older Java version, use the latest (stable) version, you will have interesting new features, and also the compiled application will benefit from all the new optimizations.

Fresh install

  1. Delete your local Android folder, usually in the home directory
  2. Download Android studio
  3. Once installed, open Settings, Search Android SDK and open it
  4. In SDK Platforms select the target Android version for your app
  5. In SDK Tools tab, select Android SDK Build-Tools, Android SDK Command-line Tools (latest), Android Emulator, Android SDK Platform-Tools
  6. Before pressing OK, check that Android SDK Location path is correct for you
  7. Press OK and let Android Studio download & install everything

(Optional) if you need to use the installed binaries from command line, be sure to add their folder into your PATH variable. If you use Android studio, it's should not be required though.

I've got Java 14 installed on my machine, anyway you can use the jre shipped with Android Studio.

Eady answered 4/12, 2020 at 18:4 Comment(0)
S
3

In my case I didn't have the required sdk version installed on my machine.

So make sure that you have installed the sdk version which is given in the error.

Here you can navigate check & install via Android Studio.

Android Stuido SDK Manager

Secure answered 20/3, 2021 at 10:40 Comment(0)
C
2

For Linux users (I'm using a Debian Distro, Kali) Here's how I resolved mine.

If you don't already have jdk-8, you want to get it at oracle's site

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

I got the jdk-8u191-linux-x64.tar.gz

Step 1 - Installing Java Move and unpack it at a suitable location like so

$ mv jdk-8u191-linux-x64.tar.gz /suitablelocation/
$ tar -xzvf /suitablelocation/jdk-8u191-linux-x64.tar.gz

You should get an unzipped folder like jdk1.8.0_191 You can delete the tarball afterwards to conserve space

Step 2 - Setting up alternatives to the default java location

$ update-alternatives --install /usr/bin/java java /suitablelocation/jdk1.8.0_191/bin/java 1
$ update-alternatives --install /usr/bin/javac javac /suitablelocation/jdk1.8.0_191/bin/javac 1

Step 3 - Selecting your alternatives as default

$ update-alternatives --set java /suitablelocation/jdk1.8.0_191/bin/java
$ update-alternatives --set javac /suitablelocation/jdk1.8.0_191/bin/javac

Step 4 - Confirming default java version

$ java -version

Notes

  1. In the original article here: https://forums.kali.org/showthread.php?41-Installing-Java-on-Kali-Linux, the default plugin for mozilla was also set. I assume we don't really need the plugins as we're simply trying to develop for android.
  2. As in @spassvogel's answer, you should also place a @repositories.cfg file in your ~/.android directory as this is needed to update the tools repo lists
  3. Moving some things around may require root authority. Use sudo wisely.
  4. For sdkmanager usage, see official guide: https://developer.android.com/studio/command-line/sdkmanager
Clorindaclorinde answered 4/12, 2018 at 19:15 Comment(0)
W
2

This question has multiple answers depending on the underlying issue. There are also multiple answers that indirectly fix the actual problem.

The core issues are:

  1. Android SDK tools have issues with the latest Oracle JDK. You can use the latest Open JDK. (The latest OpenJDK comes with Android Studio.)

  2. You don't have the latest Android SDK command line tools installed.

  3. You have the latest Android SDK command line tools installed, but you are using E:\Android\Sdk\tools\bin instead of E:\Android\Sdk\cmdline-tools\latest\bin.

Here are systematic steps to identify and fix any of the above issues that you may have.

  1. Point environment variables to your OpenJDK installation in Android Studio. Depending on your installation that is found here: E:\Program Files\Android\Android Studio\jre. You have to go through all the necessary variables like PATH, JAVA_HOME, JAVA_BIN etc and make sure that they all point to your OpenJDK.

Note: You don't have to uninstall/reinstall JDKs. That simply probably fixes your variables above as a side effect.

  1. Check that your environment variables are correct (Windows: echo %JAVA_HOME%, echo %PATH%, where javac, etc.)

  2. Go to Android Studio. In Settings, navigate to "Appearances & Behavior > System Settings > Android SDK." Install "Android SDK Command Line Tools."

  3. In the shell, go to E:\Android\Sdk\cmdline-tools\latest\bin and run sdkmanager --install "cmdline-tools;latest"

Additional troubleshooting tips: I had Android environment variables messed up as well. Run 'flutter doctor -v' and the output will help you troubleshoot additional environment configuration issues.

Without answered 27/9, 2022 at 21:29 Comment(0)
P
1

For windows machine uninstall the JDK if its more than 1.8.172. Install JDK 1.8.172

I was facing the same issue in windows 10 with java 10. I uninstalled the java 10 and installed java8 its working fine for me now :)

Paranoid answered 2/6, 2018 at 19:8 Comment(0)
T
1

Run java -version and javac -version commands in a command line to make sure that they come from the same JDK (eg: version 1.8.0_181)

If not, you have to modify PATH variable so that it only points to a single JDK. If you are not sure how to, just uninstall all other Java instances except for Java 8 (Add/Remove Programs in Windows). As for today, both Unity and Android recommends that you use JDK 8.

With Java 8, it is not necessary to export java.se.ee module as shown in some of the other answers. You may also remove any JAVA_OPTS or other environment variables that you have set.

Trueman answered 14/9, 2018 at 4:47 Comment(0)
S
1

Downgrade your java version.Whatever system or ide.

Make sure java version is not higher than 8

In my case.I change the ide java verion.This solves my issue. enter image description here

Slade answered 11/4, 2019 at 12:42 Comment(0)
F
1

I had recently solved this problem by uninstalling the higher version of JDK and installing JDK 8. After installing the JDK you need to give the path. Then you need to open command prompt in "C:\Users\Milan Adhikari\AppData\Local\Android\Sdk\tools" and run "sdkmanager --update" which will update your sdk and then you need to run "flutter doctor --android-licenses" in cmd and accept all the licenses.
Now your problem should be solved.

Froe answered 30/3, 2020 at 17:13 Comment(0)
E
1

Best way is to use below command

   $ wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
   $ unzip \platform-tools-latest-linux.zip
   $ sudo cp platform-tools/adb /usr/bin/adb
   $ sudo cp platform-tools/fastboot /usr/bin/fastboot

Now run adb version to verify it’s been updated.

Elastin answered 9/5, 2020 at 15:8 Comment(0)
H
1

No need to uninstall your other java version(s) that's already installed on your machine. Whenever required, you can conveniently use the utility 'update-alternatives' to choose the Java runtime that you wish to activate. It will automagically update the required symbolic links.

You just need to run the below command and select the version of your choice. That's all!

sudo update-alternatives --config java
Hanzelin answered 24/10, 2020 at 9:41 Comment(0)
S
1

As @steven pointed out, install Java 8 (here a link for Ubuntu 16.04, 18.04 and 20.04/20.10 https://computingforgeeks.com/how-to-install-java-8-on-ubuntu/) and then set it as the default Java version with this command:

sudo update-alternatives --config java
Shiver answered 26/10, 2020 at 17:40 Comment(0)
P
0

When your Android stuio/jre uses a differ version of java, you will receive this error. to solve it, just set Android studio/jre to your JAVA_HOME. and uninstall your own java.

Pavid answered 15/7, 2019 at 7:24 Comment(0)
S
0

For me i install java version 8 and just select the java version in "JDK location": enter image description here

Straightedge answered 15/12, 2019 at 10:8 Comment(0)
M
0

For my circumstance, I'm using sdkman to manage multiple java versions. I set default java version to 13. Install version 8 and now it's working fine.

Marsupial answered 3/2, 2020 at 1:50 Comment(0)
G
0

I was having the same issue and had installed openjdk-8-jdk as suggested. Checking javac -version resulted in the correct version, but java -version showed version 11.

The solution was to use:

sudo update-alternatives --config java

and select version 8 from the menu.

Groth answered 30/10, 2020 at 19:50 Comment(0)
A
0

My Java version is 15.0.1 . For the OS Mac.

and this is how i fixed the issue.

  1. downloaded zip: jaf-1_1_1.zip from: https://download.oracle.com/otn-pub/java/jaf/1.1.1/jaf-1_1_1.zip?AuthParam=1609860571_68ca6f30491c76e81970a3849504fb6a

  2. downloaded the zip: jaxb-ri-2.3.1.zip from: https://download.oracle.com/otn-pub/java/jaf/1.1.1/jaf-1_1_1.zip?AuthParam=1609860571_68ca6f30491c76e81970a3849504fb6a

  3. unziped into a folder: ~/jars/ . exported classpath as follows

export  
 CLASSPATH=~/jars/FastInfoset.jar:~/jars/activation.jar:~/jars/codemodel.jar:~/jars/dtd-parser.jar:~/jars/istack-commons-runtime.jar:~/jars/istack-commons-tools.jar:~/jars/jaf-1.1.1:~/jars/jaf-1_1_1.zip:~/jars/javax.activation-api.jar:~/jars/jaxb-api.jar:~/jars/jaxb-jxc.jar:~/jars/jaxb-ri:~/jars/jaxb-ri-2.3.1.zip:~/jars/jaxb-runtime.jar:~/jars/jaxb-xjc.jar:~/jars/relaxng-datatype.jar:~/jars/rngom.jar:~/jars/stax-ex.jar:~/jars/txw2.jar:~/jars/xsom.jar
  1. next edit the file: cd ~/Library/Android/sdk/tools/bin/sdkmanager change the CLASSPATH to the below

CLASSPATH=$CLASSPATH:$APP...

save the file and run the command again.

Apomict answered 5/1, 2021 at 16:28 Comment(0)
S
0

Updated my current Android SDK and everything worked like a charm.

Suppressive answered 24/3, 2021 at 18:25 Comment(0)
D
0

Got this error running "flutter doctor --android-licenses" In Windows 10. I solved it creating these two environment variables

ANDROID_SDK_ROOT
C:\Users\youruser\AppData\Local\Android\Sdk

ANDROID_SDK_HOME
C:\Users\youruser\.android

Refresh environment variables or reboot and then run the command again.

Detoxify answered 9/11, 2021 at 9:7 Comment(0)
J
0

I know this is an old question, however, another way to fix this error is by connecting an Android phone to your laptop (i.e. run the app on a physical device). Ensure the USB debug mode is enabled. enter image description here

Jeffers answered 14/7, 2023 at 19:26 Comment(1)
yep, apparently my PC wasn't detecting my phone and I had to add it againPetropavlovsk

© 2022 - 2024 — McMap. All rights reserved.