flutter java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

  • Post author:
  • Post category:java


今天执行 flutter doctor -v 的时候发现一个问题,提示信息是

[!] Android toolchain – develop for Android devices (Android SDK version 30.0.2)

• Android SDK at /Users/zhaopingfu/Library/Android/sdk

• Platform android-S, build-tools 30.0.2

• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java

• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

✗ Android license status unknown.

Run `flutter doctor –android-licenses` to accept the SDK licenses.

See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

1

2

3

4

5

6

7

8

然后根据提示信息执行 flutter doctor –android-licenses,发现报错了,错误信息是

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

… 5 more

1

2

3

4

5

6

7

8

9

10

11

通过 java -version 查看了 java 版本是 1.8

java version “1.8.0_281”

Java(TM) SE Runtime Environment (build 1.8.0_281-b09)

Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

1

2

3

网上好多说是 jdk 版本的问题,但是我的 jdk 就是 1.8,尝试了 jdk 升级到 11 再回退到 1.8 还是不行,所以排除这种情况

最后通过查找各种资料找到了解决办法

打开 AndroidStudio 中的 SdkManager

下载最新版本的 Android SDK Command-lines Tools,如下图所示

重新运行 flutter doctor –android-licenses,提示信息为

[=========                              ] 25% Fetch remote repository…

7 of 9 SDK package licenses not accepted. 100% Computing updates…

Review licenses that have not been accepted (y/N)?

1

2

3

运行 flutter doctor -v,提示信息为

• No issues found!

1

参考资料: https://www.dev2qa.com/how-to-fix-java-lang-noclassdeffounderror-javax-xml-bind-annotation-xmlschema-when-install-android-sdk/