Tuesday, August 24, 2021

Flutter: "main" java.lang.NoClassDefFoundError: when running flutter doctor --android-license


$ 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


Solution:

Install Android SDK Command-line Tools (latest) from Android Studio via 

Android Studio > Preferences.. > Appaearance & Behavior > System Settings > Android SDK






check the Android SDK Command-line Tools (latest) option from SDK Tools tab and click Apply







then run flutter doctor --android-licenses and accept lienses

$ flutter doctor --android-licenses

10.8 Open Source Software. In the event Open Source software is included with Evaluation Software, such Open Source software is licensed pursuant to the applicable Open Source software license agreement identified in the Open Source software comments in the applicable source code file(s) and/or file header as indicated in the Evaluation Software. Additional detail may be available (where applicable) in the accompanying on-line documentation. With respect to the Open Source software, nothing in this Agreement limits any rights under, or grants rights that supersede, the terms of any applicable Open Source software license agreement.

---------------------------------------

Accept? (y/N): y

All SDK package licenses accepted


Try running flutter doctor again to see if no errors.


$ flutter doctor -v

[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-x64, locale en-US)

    • Flutter version 2.2.3 at /Users/xx/flutter

    • Framework revision f4abaa0735 (8 weeks ago), 2021-07-01 12:46:11 -0700

    • Engine revision 241c87ad80

    • Dart version 2.13.4


[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)

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

    • Platform android-31, build-tools 31.0.0

    • ANDROID_HOME = /Users/xx/Library/Android/sdk

    • Java binary at: /Applications/Android

      Studio.app/Contents/jre/jdk/Contents/Home/bin/java

    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

    • All Android licenses accepted.


[✓] Xcode - develop for iOS and macOS

    • Xcode at /Applications/Xcode.app/Contents/Developer

    • Xcode 12.5.1, Build version 12E507

    • CocoaPods version 1.10.0


[✓] Chrome - develop for the web

    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome


[✓] Android Studio (version 2020.3)

    • Android Studio at /Applications/Android Studio.app/Contents

    • Flutter plugin can be installed from:

      🔨 https://plugins.jetbrains.com/plugin/9212-flutter

    • Dart plugin can be installed from:

      🔨 https://plugins.jetbrains.com/plugin/6351-dart

    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)


[✓] IntelliJ IDEA Ultimate Edition (version 2020.2.3)

    • IntelliJ at /Applications/IntelliJ IDEA.app

    • Flutter plugin can be installed from:

      🔨 https://plugins.jetbrains.com/plugin/9212-flutter

    • Dart plugin can be installed from:

      🔨 https://plugins.jetbrains.com/plugin/6351-dart


[✓] VS Code (version 1.58.2)

    • VS Code at /Applications/Visual Studio Code.app/Contents

    • Flutter extension version 3.24.0


[✓] Connected device (2 available)

    • macOS (desktop) • macos  • darwin-x64     • macOS 11.5.1 20G80 darwin-x64

    • Chrome (web)    • chrome • web-javascript • Google Chrome 92.0.4515.159


• No issues found!


Done. 

No comments: