flutter doctor --android-licenses gives a java error

强颜欢笑 提交于 2021-02-06 14:46:29

问题


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:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 5 more

I get this error above when running flutter doctor --android-licenses. Does anyone know why this is happening and how I can fix it? I'm already running it on the flutter console.


回答1:


Installing Android SDK Command-line tools from Android SDK Manager did the job for me.

  1. Open Tools > SDK Manager
  2. From the left choose, Appearance & Behavior > System Settings > Android SDK
  3. Select SDK Tools from the top menu
  4. Check Android SDK Command-line tools and click 'apply'.



回答2:


Install Android SDK Command-line tools from Android SDK Manager solved my problem.

  1. Open Tools -> SDK Manager
  2. Appearance & Behavior > System Settings > Android SDK
  3. Select SDK Tools from the top menu. Check Android SDK Command-line tools and click 'apply'



回答3:


On Linux

Android SDK only works with JDK 8 so uninstall your current JDK version.

Past the command and press tab for autocomplete, remove all the things that it shows you that starts with openjdk-

sudo apt remove openjdk-

and now install JDK 8

sudo apt install openjdk-8-jdk



回答4:


I recommend clearing the android-studio-dir and android-sdk settings, and let flutter automatically detects their path instead: This works for me .

flutter config --android-studio-dir=""

flutter config --android-sdk=""



回答5:


It seems you are getting a JDK exception, it happens when you does not have JAVA_HOME setted on your system variables OR you have almost setted the JDK but in the wrong folder OR you are trying to run the SDK Manager (which allows you to accept the Android Licenses) with the wrong JDK.

In case of JDK 9 or higher:

Actually, Android SDK Manager works only with Gradle compiled on version of JDK 8 for Android development, so, if you have a most-recent JDK version already setted on system variables, consider to downgrade it to the JDK version 8.

This version works fine for me: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

In case of JDK 8 already installed

If you manually extracted the JDK folder to a directory, maybe you have setted it "wrong". I mean: You pointed the wrong way to the bin Java folder, but it still works. You have to set JAVA_HOME as the root of JDK, example: In the JDK zipped folder, you have to extract it and point the system variable in the unzipped folder, no directly in the bin directory, you have to point JAVA_HOME as a system variable and declare the bin folder as an executable.

Examples:

Linux

In your shell configuration file:

export JAVA_HOME="/home/user/jdk1.8.0_261"
export PATH="$PATH:$JAVA_HOME/bin"

Windows

In your environment variables manager:

Set a new SYSTEM VARIABLE named JAVA_HOME

Then, edit the PATH variable and add a new register to it:

%JAVA_HOME%\bin

Actually, I don't know really how to manage JDKs in MacOS, if that is you OS, sorry :(

Hope it helps!




回答6:


My solution was: I had Android SDK Build-Tools, Android Emulator and Android SDK Platform-Tools installed. Also I had JAVA_HOME variable in environments variables.

So I decided to uninstall Android SDK Build-Tools, Android Emulator and Android SDK Platform-Tools and install them again. Moreover, I deleted JAVA_HOME variable. And after these operations I run flutter doctor --android-licenses in terminal. And somehow it worked out.



来源:https://stackoverflow.com/questions/61993738/flutter-doctor-android-licenses-gives-a-java-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!