简体   繁体   English

flutter doctor --android-licenses 给出了 java 错误

[英]flutter doctor --android-licenses gives a java 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: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.运行 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.我已经在 flutter 控制台上运行它。

Installing Android SDK Command-line tools from Android SDK Manager did the job for me.Android ZF20E3C5E54C0AB3D376AZD660B3F86安装Android SDK 命令行工具ZF20E3C5E54C0AB3D3765D660B3F86

  1. Open Tools > SDK Manager打开工具> SDK 管理器
  2. From the left choose, Appearance & Behavior > System Settings > Android SDK从左侧选择,外观和行为>系统设置> Android SDK
  3. Select SDK Tools from the top menu Select SDK顶部菜单中的工具
  4. Check Android SDK Command-line tools and click 'apply'.检查Android SDK 命令行工具并单击“应用”。

Alternative to step #1: WINDOWS: File > Settings (Ctrl+Alt+S) / MAC: Android Studio > Preferences替代步骤 #1:WINDOWS:文件>设置(Ctrl+Alt+S) / MAC: Android Studio >首选项


在此处输入图像描述

If you are facing a problem in spite of the above steps, you can try upgrading your system to JDK 8. Official documentation of upgrading to JDK 8 is available here .如果您在执行上述步骤后仍遇到问题,可以尝试将系统升级到 JDK 8。升级到 JDK 8 的官方文档可在此处获得。

I'm a Mac user and I solve this issue.我是 Mac 用户,我解决了这个问题。

This answer also helps Windows users and Linux users solve the issue from the user's feedback.这个答案也帮助 Windows 用户和 Linux 用户解决了用户反馈的问题。

At the first, this is what I met for the issue起初,这是我遇到的问题
$ flutter doctor -v $ flutter 医生-v 在此处输入图像描述

And the following command is not work for my situation.以下命令不适用于我的情况。
$ flutter doctor --android-licenses $ flutter 医生 --android-licenses 在此处输入图像描述

The way to solve this is to install解决这个问题的方法是安装
Android SDK Command-line Tools . Android SDK 命令行工具 And how?如何?
You just need to do it by the following two steps.您只需要通过以下两个步骤来完成。

Install: Android SDK Command-line Tools安装:Android SDK 命令行工具

Step 1. Open SDK Manager步骤 1. 打开 SDK 管理器
Top Menu -> Tools -> SDK Manager顶部菜单 -> 工具 -> SDK 管理器在此处输入图像描述

Step 2. Install command-line tools步骤 2. 安装命令行工具

  1. Unfold Appearance & Behavior展开外观和行为
  2. Unfold System Settings展开系统设置
  3. Click Android SDK点击Android SDK
  4. Click tab of SDK Tools单击SDK 工具的选项卡
  5. Check Android SDK Command-line Tools (latest)检查Android SDK 命令行工具(最新)
  6. Click Apply button.单击应用按钮。 在此处输入图像描述 Then click OK button to finish installation.然后单击确定按钮完成安装。

Keep going to sign android licenses.继续签署 android 许可证。

After Android Studio finishing install, you can do the following. Android Studio 完成安装后,您可以执行以下操作。
$ flutter doctor --android-licenses $ flutter 医生 --android-licenses
在此处输入图像描述 After saying yes many times, all android licenses have been signed.多次说yes后,android的license都签完了。

Check by flutter doctor again.再次由 flutter 医生检查。

$ flutter doctor -v $ flutter 医生-v
在此处输入图像描述

You can see that All Android licenses accepted.您可以看到所有 Android 许可证都已接受。

Congratulations, you have completed this task!恭喜你,你已经完成了这个任务!

i had the same problem, solved it by installing the coomand-line tools from android studio我有同样的问题,通过安装 android 工作室的 coomand-line 工具解决了它

click on file, settings then on the search bar type sdk and click in android sdk点击文件,设置,然后在搜索栏输入 sdk 并点击 android sdk 安卓 SDK

Then click on sdk tools, check the android command-line tools box, the click on apply allow to download.然后点击sdk工具,勾选android命令行工具框,点击应用允许下载。 then try running flutter doctor --android-licenses again on your cmd you will be prompted to accept licenses然后尝试在您的 cmd 上再次运行flutter doctor --android-licenses您将被提示接受许可证

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.似乎您遇到了 JDK 异常,它发生在您没有在系统变量上设置JAVA_HOME或者您几乎设置了 JDK 但在错误的文件夹中或者您正在尝试运行 SDK 管理器(它允许您接受Android 许可证)使用错误的 JDK。

In case of JDK 9 or higher:如果是 JDK 9 或更高版本:

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. 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这个版本对我来说很好用: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

In case of JDK 8 already installed如果已安装 JDK 8

If you manually extracted the JDK folder to a directory, maybe you have setted it "wrong".如果你手动将JDK文件夹解压到一个目录下,可能是你设置的“错误”。 I mean: You pointed the wrong way to the bin Java folder, but it still works.我的意思是:您将错误的方式指向bin Java 文件夹,但它仍然有效。 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.必须将JAVA_HOME设置为JDK的根目录,例如:在JDK压缩文件夹中,您必须将其解压并指向解压文件夹中的系统变量,而不是直接在bin目录中,您必须将JAVA_HOME指向为系统变量并将 bin 文件夹声明为可执行文件。

Examples:例子:

Linux Linux

In your shell configuration file:在您的 shell 配置文件中:

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

Windows Windows

In your environment variables manager:在您的环境变量管理器中:

Set a new SYSTEM VARIABLE named JAVA_HOME设置一个名为 JAVA_HOME 的新系统变量

在此处输入图像描述

Then, edit the PATH variable and add a new register to it:然后,编辑 PATH 变量并向其中添加一个新寄存器:

%JAVA_HOME%\bin

Actually, I don't know really how to manage JDKs in MacOS, if that is you OS, sorry:(实际上,我真的不知道如何在 MacOS 中管理 JDK,如果那是你的操作系统,对不起:(

Hope it helps!希望能帮助到你!

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.运行 flutter 医生 --android-licenses 时出现上述错误。 Does anyone know why this is happening and how I can fix it?有谁知道为什么会发生这种情况以及我该如何解决? I'm already running it on the flutter console.我已经在 flutter 控制台上运行它。

On Linux在 Linux

Android SDK only works with JDK 8 so uninstall your current JDK version. Android SDK仅适用于JDK 8 ,因此请卸载当前的JDK版本。

Past the command and press tab for autocomplete, remove all the things that it shows you that starts with openjdk-通过命令并按 Tab 键进行自动完成,删除它显示的所有以openjdk-开头的内容-

sudo apt remove openjdk-

and now install JDK 8现在安装JDK 8

sudo apt install openjdk-8-jdk

You need JDK 8 since the required files were removed in later versions.您需要 JDK 8,因为在更高版本中删除了所需文件。

Once installed you can switch between versions using安装后,您可以使用在版本之间切换

sudo update-alternatives --config java

then select the option for JDK 8. This will also show you the location of your JDK 8 installation which you'll need for:然后是 select JDK 8 的选项。这还将显示您需要的 JDK 8 安装位置:

export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
PATH=$PATH:$JAVA_HOME/bin

I recommend clearing the android-studio-dir and android-sdk settings, and let flutter automatically detects their path instead: This works for me.我建议清除 android-studio-dir 和 android-sdk 设置,让 flutter 自动检测它们的路径:这对我有用。

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

first of all you need to know that flutter works on jdk 8, so if you have other versions installed you need to purge them so as to completely remove other versions首先你需要知道 flutter 适用于 jdk 8,所以如果你安装了其他版本,你需要清除它们以完全删除其他版本

NOTE: this is according to my case Ubuntu 20.04, THIS IS ACCORDING TO MY SITUATION IT IS NOT GUARANTEED TO WORK FOR YOU注意:这是根据我的情况 Ubuntu 20.04,这是根据我的情况,不保证为您工作

if you have jdk 11, to uninstall use one of the two commands depending on the one that you had installed or you can run both of them if you do not know which one of them is installed on your machine.如果您有 jdk 11,要卸载使用这两个命令之一,具体取决于您已安装的命令,或者如果您不知道您的机器上安装了哪一个命令,则可以同时运行这两个命令。

sudo apt purge openjdk-11-jre-headless

sudo apt purge openjdk-11-jre

if it is any other version replace 11 with that number.如果是任何其他版本,请将 11 替换为该数字。 if you use the default jdk then to uninstall use the following command如果您使用默认 jdk,则使用以下命令卸载

sudo apt purge default-jre

to make sure we remove everything related with java run this command确保我们删除与 java 相关的所有内容,运行此命令

sudo apt auto remove

NOTE: you can run all the above commands just to be more sure you fully remove everything related with java注意:您可以运行上述所有命令,以确保完全删除与 java 相关的所有内容

to verify that we have removed everything run验证我们已删除所有运行

java -v

if you see the error below or java version then java has not been uninstalled如果您看到以下错误或 java 版本,则 java 尚未卸载

Unrecognized option: --version
Error: Could not create the Java Virtual Machine. 
Error: A fatal exception has occurred. Program will exit.

but if you get response that java was not found and there are java installation suggestion it means java has been uninstalled但是如果你得到回应说 java 没有找到并且有 java 安装建议这意味着 java 已被卸载

now we need to install jdk 8 run this command现在我们需要安装 jdk 8 运行这个命令

sudo apt install openjdk-8-jre

if everything goes well reboot your machine and run flutter doctor and follow the instructions to accept the licenses如果一切顺利,重新启动您的机器并运行flutter doctor并按照说明接受许可证

Regards, hope this post becomes helpful to you问候,希望这篇文章对你有所帮助

The above solutions totally work, but there's a solution that I see fewer times than I would expect: sdkman => https://sdkman.io/上述解决方案完全有效,但我看到的解决方案比我预期的要少:sdkman => https://sdkman.io/

with such a tool installed, changing java version is quick as ( Adopt java 8 as example):安装了这样的工具,更改 java 版本很快(以 java 8 为例):

❯ sdk install java 8.0.282.hs-adpt
❯ sdk use java 8.0.282.hs-adpt

My solution was: I had Android SDK Build-Tools, Android Emulator and Android SDK Platform-Tools installed. 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.我也在环境变量中有JAVA_HOME变量。

So I decided to uninstall Android SDK Build-Tools, Android Emulator and Android SDK Platform-Tools and install them again. 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.此外,我删除JAVA_HOME变量。 And after these operations I run flutter doctor --android-licenses in terminal.在这些操作之后,我在终端中运行flutter doctor --android-licenses And somehow it worked out.不知何故,它成功了。

For me, on Windows 10, the answer was simply to remove the JAVA_HOME environment variable.对我来说,在 Windows 10 上,答案只是删除 JAVA_HOME 环境变量。

This probably isn't a good idea if you're a Java developer, or you rely on some Java software to do your work, but if you're a dev that doesn't work in the Java space and you're just getting started with Flutter like I am, then go into the system environment variables and kill that one.如果您是 Java 开发人员,或者您依赖某些 Java 软件来完成您的工作,那么这可能不是一个好主意,但如果您是一个无法在 ZD52387880E1EA2283819Z 空间中工作的开发人员,那么您只需获得 375921113817A72像我一样从 Flutter 开始,然后 go 进入系统环境变量并杀死那个。 flutter doctor --android-licenses worked like it is supposed to after I did that. flutter doctor --android-licenses在我这样做之后就像它应该的那样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM