YAnubhav Chetan
YAnubhav Chetan

Reputation: 39

Java 17 and Android SDK

Hii I want to know if Android sdk is compatible with Java version 17.0.1 ??

Actually I am trying to build an application with command line.... For that I have installed Gradle, java and also installed Android sdk and it's packages like 'command-line tools' , 'platform tools' etc...

But when I tried to run sdkmanager it shows this

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: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

I have searched the internet and found out that I have to downgrade my java version to 8.... But I don't want to downgrade it..

Upvotes: 3

Views: 977

Answers (2)

MendasD
MendasD

Reputation: 1

I had the same issue, and I resolved it by following these steps:

Download and install OpenJDK 17 from Adoptium(https://adoptium.net/fr/download/) or Oracle JDK. Set the JAVA_HOME environment variable to point to the Java 17 installation directory. Then, you should restart the cmd window After that, running flutter doctor --android-licenses worked without issues.

Upvotes: 0

Quintin Henn
Quintin Henn

Reputation: 91

You probably have an older version of the sdkmanager sitting on your system path.

This is an issue with Android Studio, when not updating the application for a long time (I was not using it for almost a year) the tools/bin folder can go stale (this is the main SDK Tools installation folder I am referring to).

Short easy solution:
Remove ANDROID_HOME/tools/bin from your system path.

The SDK Tools environment variables page and some other tools (in my case I used Cordova to build android application) suggest adding that folder to your path, but I would think that external application should rather use the cmdline-tools to interact with the Android environment.

So removing it from your path shouldn't have any impact.

Where the issue was for me:

.
└── ANDROID_HOME
    ├── build-tools
    ├── cmdline-tools
    |   └── latest
    |       └── bin <- new latest tools
    ├── emulator
    ├── extras
    ├── ndk
    ├── platforms
    ├── platform-tools
    ├── sources
    ├── system-images
    └── tools
        └── bin <- out of date tools

If you look in the ANDROID_HOME/cmdline-tools/latest/bin and open the sdkmanager.bat or avdmanager.bat in a text editor. I found a check for Java 17.

if !version! lss 170 if "%SKIP_JDK_VERSION_CHECK%" == "" (
  echo Java version 17 or higher is required.
  echo To override this check set SKIP_JDK_VERSION_CHECK
  goto :eof
)

The ANDROID_HOME/tools/bin files did not do that checked and worked only on Java 8. Having both folders with the same file names on the system path, in this case, the older version was used.

I reinstalled the Android SDK, build-tools and cmdline-tools. etc. by uninstalling and installing again. This fixed some other issues for me, but it did not matter how many time I reinstalled the tools, the tools/bin folder never updated to the latest version.

A better solution to this problem is maybe to just uninstall Android Studio and delete the ANDROID_HOME directory. Then reinstall everything again.

Upvotes: 0

Related Questions