Nativescript-cli: Android SDK is not installed or is not configured properly, environment looks ok

Created on 28 Sep 2017  路  25Comments  路  Source: NativeScript/nativescript-cli

See #1813. This problem STILL EXISTS - despite that issue being closed for some reason - on Linux, and on Mac.

@Rombersoft
@bboydflo

known limitation

Most helpful comment

Or just export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'. On Bash, YMMV.

All 25 comments

@ItStillDoesNotWork please follow the issue template when filing an issue.

Make sure you have all the required Android SDK packages installed too, these include SDK Platform 25, Android SDK Build-Tools 25.0.2 or later, Android Support Repository, Google Repository and any other SDKs that you may need.

sudo $ANDROID_HOME/tools/bin/sdkmanager "tools" "platform-tools" "platforms;android-25" "build-tools;25.0.2" "extras;android;m2repository" "extras;google;m2repository"

As per http://docs.nativescript.org/start/ns-setup-linux#advanced-setup-steps

Hi,

Got the same issue when updating NativeScript to 3.2.1, I think it comes from the script installation which does everything for you and change your bash_profile.. A lots of MacOsX users use Zsh it may comes from this.
(javac works in the terminal)

tns --version:
3.2.1

get an error while executing:

sudo $ANDROID_HOME/tools/bin/sdkmanager "tools" "platform-tools" "platforms;android-25" "build-tools;25.0.2" "extras;android;m2repository" "extras;google;m2repository"

error:

sudo $ANDROID_HOME/tools/bin/sdkmanager "tools" "platform-tools" "platforms;android-25" "build-tools;25.0.2" "extras;android;m2repository" "extras;google;m2repository"
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:103)
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)
    ... 4 more

.bash_profile:

source ~/.profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

###-tns-completion-start-###
if [ -f /Users/rhanb/.tnsrc ]; then
    source /Users/rhanb/.tnsrc
fi
###-tns-completion-end-###
export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1
export JAVA_HOME=/Library/Java/Home
export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1
export JAVA_HOME=/Library/Java/Home

.zshrc:

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/usr/local/opt/android-sdk

when updating I also got this errors:

Configuring your system for Android development... This might take some time, please, be patient.
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:103)
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)
    ... 4 more
WARNING: There seem to be some problems with the Android configuration
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:103)
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)
    ... 4 more

Hope it can help

Hey @rhanb which JDK distribution do you have? Please make sure it's Oracle's 1.8 (Java 8) JDK.

Hey @Pip3r4o ,

Thanks for your answer, I used the latest JDK which was downloaded from the NativeScript script which run when I updated it. Using Java 8 SDK fixed the issue 馃憤

Hi @rhanb, the setup script was updated to require explicitly Java 8 and the documentation was updated accordingly.

I ran into this problem and found a solution that worked for me here:
https://stackoverflow.com/questions/47150410/failed-to-run-sdkmanager-list-android-sdk-with-java-9

Namely:
replacing line 31 of $ANDROID_HOME/tools/bin/sdkmanager:

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

Or just export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'. On Bash, YMMV.

I am getting the exact same behavior as rhanb described above, but I am on JDK 8 (1.8), and I have tried the fix GrumpyOldTroll offered - still getting the same errors.

Android Tools are not yet compatible with JDK 9 or 10 and by taking a look at the XmlSchema error it looks like at some point the system is using the system-wide JDK version. If you have to work with multiple Java versions (and just having a JDK 8 is not an option) you can try this: https://stackoverflow.com/questions/49630165/how-to-configure-unity-2017-4-to-target-android-and-avoid-build-failures-on-osx/49630166#49630166
(I work with multiple Java versions via jenv and this was the only sane solution I found)

Getting same issue

I using the currenty version of tns (5.1.0), and i solved the problem removing "--add-modules java.se.ee'"

# OLD: 
# DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.." -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee # 
NEW: 
DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.." -XX:+IgnoreUnrecognizedVMOptions

Thanks to @GrumpyOldTroll for the path to solve this.

I using the currenty version of tns (5.1.0), and i solved the problem removing "--add-modules java.se.ee'"

# OLD: 
# DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.." -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee # 
NEW: 
DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.." -XX:+IgnoreUnrecognizedVMOptions

Thanks to @GrumpyOldTroll for the path to solve this.

Great! Its work

I use it in windows:

@rem Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
@rem set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.." -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee

I solved the problem on Linux

  • mov the sdk files to home folder like /home/user_name/android/sdk
  • change ANDROID_HOME path with the new path ( in .bashrc file and source it or reopen the terminal )
  • call the same command without sudo
    $ANDROID_HOME/tools/bin/sdkmanager "tools" "emulator" "platform-tools" "platforms;android-28" "build-tools;28.0.3" "extras;android;m2repository" "extras;google;m2repository"

i solved it downgrading to java 8

If you want to read how to properly install java 8, here is the link: https://www.dev2qa.com/how-to-install-uninstall-multiple-java-versions-in-mac-os-by-home-brew-or-manually/

Just downgrade your Java version to Java 8 using this: sudo update-alternatives --config java :+1:

Already Solved At Here

I don't understand why Oracle removed (or just moved) the XmlSchema classes. For anyone with a modern version of Java installed this error exists. Also, at least for Windows, you can't download JDK 8 anymore without signing up for an Oracle account.

Once JDK 8 is installed this all seems to work. Unfortunately, I need a newer release of Java for other workloads, so I keep needing to adjust JAVA_HOME and my PATH depending on what I'm doing at the time. Hopefully these tools will be updated to remove the dependency on JDK8.

Just downgrade your Java version to Java 8 using this: sudo update-alternatives --config java

It solved here! Thanks!

Am facing the same issue while upgrading licenses in flutter doctor
help me please to solve this..Thanks in Advance

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(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:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more

I have faced two errors while Build my project on Android Studio:

1) License for package Android SDK Platform 28 not accepted. (while Build my project in Android Studio 4.1)

2) exception in thread main java.lang.noclassdeffounderror javax/xml/bind/annotation/xmlschema (while running SDK manager to accept license)

For me, it was a java version problem. I have installed JDK instead of java. TO SOLVE THE ISSUE, I did the following steps.

For Windows:

Step1: Download and install the latest JAVA version from https://www.java.com/en/download/

Step2: Search for "View advanced system settings" in the start menu button (windows icon)

Step3: Click on "Environment Variables"

Step4: under "System variables" click on "New", now set "Variable name: JAVA_HOME" and "Variable value: C:\Program Files\Java\jre1.8.0_271" (add latest installed java path here). Then "OK", "OK", and "OK".

Step5: open cmd as an administrator and type the following commands:

1) cd C:\Users\kevin\AppData\Local\Android\Sdk\tools\bin (*change username here)

2) sdkmanager --licenses

Press "y" for all questions.

Step6: Restart your Android Studio again.

DONE.

Let me know if anyone having a problem while following the above steps.

Am facing the same issue while upgrading licenses in flutter doctor
help me please to solve this..Thanks in Advance

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(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:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more

Were you able to get any solution to this. I am getting the same error message in mac when I run
flutter doctor --android-licenses

I have faced two errors while Build my project on Android Studio:

  1. License for package Android SDK Platform 28 not accepted. (while Build my project in Android Studio 4.1)
  2. exception in thread main java.lang.noclassdeffounderror javax/xml/bind/annotation/xmlschema (while running SDK manager to accept license)

For me, it was a java version problem. I have installed JDK instead of java. TO SOLVE THE ISSUE, I did the following steps.

For Windows:

Step1: Download and install the latest JAVA version from https://www.java.com/en/download/

Step2: Search for "View advanced system settings" in the start menu button (windows icon)

Step3: Click on "Environment Variables"

Step4: under "System variables" click on "New", now set "Variable name: JAVA_HOME" and "Variable value: C:\Program Files\Java\jre1.8.0_271" (add latest installed java path here). Then "OK", "OK", and "OK".

Step5: open cmd as an administrator and type the following commands:

  1. cd C:\Users\kevin\AppData\Local\Android\Sdk\tools\bin (*change username here)
  2. sdkmanager --licenses

Press "y" for all questions.

Step6: Restart your Android Studio again.

DONE.

Let me know if anyone having a problem while following the above steps.

This worked on May 2021. Had to install Java 8.0.291 (latest at that time) and run the commands (for some reason, I had to use Program Files x86 instead of Program Files). Thanks

You can resolve this issue by downloading the Android SDK Command-line Tools (latest) on Android Studio, under Settings > Appearance & Behavior > System Settings > Android SDK > SDK Toolsand re-running flutter doctor --android-licenses then accept all license messages.

Was this page helpful?
0 / 5 - 0 ratings