例如,当我运行 sdkmanager 时,会显示此错误:
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:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more
如果我想在我的 Android 设备上运行任何 flutter 代码,则会出现此错误:
Launching lib/main.dart on VOG L29 in debug mode...
Checking the license for package Android SDK Build-Tools 30.0.3 in /opt/android-sdk/licenses
Warning: License for package Android SDK Build-Tools 30.0.3 not accepted.
Checking the license for package Android SDK Platform 31 in /opt/android-sdk/licenses
Warning: License for package Android SDK Platform 31 not accepted.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-31 Android SDK Platform 31
build-tools;30.0.3 Android SDK Build-Tools 30.0.3
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: /opt/android-sdk
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 17s
Running Gradle task 'assembleDebug'... 18.1s
Exception: Gradle task assembleDebug failed with exit code 1
我还尝试通过接受许可证来修复错误,但这也行不通。
答案1
简而言之,您需要
- 安装Java 8
- 设置
$JAVA_HOME
为指向它并 - 添加
$JAVA_HOME/bin
到您的$PATH
背景:sdkmanager
编译为使用 Java 8,而您的 Java 版本可能要高得多。在 Java 8 和您的 Java 版本之间,XML 绑定 API 发生了显着变化,因此sdkmanager
想要使用的类不再存在。通过恢复到较旧的 JVM,sdkmanager
将找到javax/xml/bind/annotation/XmlSchema
相关的类。
稍微深入一点:Android 使用基于 Java 8 的字节码运行时 - 由于与 Sun 和 Oracle 在与 Java 标准的兼容性方面存在分歧,它从未升级到更高版本的 JVM。