When trying to accept Android Studio licenses, I keep getting this error "java.lang.NoClassDefFoundError"

huangapple go评论87阅读模式
英文:

When trying to accept Android Studio licenses, I keep getting this error "java.lang.NoClassDefFoundError"

问题

I am trying to build my first android studio project. I keep getting this error:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

When I try to build the simplest "MyFirstApp" project, I do not get this error.

I have tried to run the sdkmanager from the terminal:

cd /Users/username/Library/Android/sdk/tools/bin
./sdkmanager --licenses

as well as by physically going to the sdkmanager directory, and double clicking on sdkmanager.

I get the same error on both. I also updated my Java. So, why do I get this error? And how do I fix it?

The full error is as follows:

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

Also, just adding it here, in case it is relevant, this is the output I get when running java --version:

java 13.0.2 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
英文:

I am trying to build my first android studio project. I keep getting this error:

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

When I try to build the simplest "MyFirstApp" project, I do not get this error.

I have tried to run the sdkmanager from the terminal:

cd /Users/username/Library/Android/sdk/tools/bin
./sdkmanager --licenses

as well as by physically going to the sdkmanager directory, and double clicking on sdkmanager.

I get the same error on both. I also updated my Java. So, why do I get this error? And how do I fix it?

The full error is as follows:

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
	at com.android.repository.api.SchemaModule$SchemaModuleVersion.&lt;init&gt;(SchemaModule.java:156)
	at com.android.repository.api.SchemaModule.&lt;init&gt;(SchemaModule.java:75)
	at com.android.sdklib.repository.AndroidSdkHandler.&lt;clinit&gt;(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:602)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 5 more

Also, just adding it here, in case it is relevant, this is the output I get when running java --version:

java 13.0.2 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)

答案1

得分: 0

我在Android Studio中检查了Gradle同步,并发现还有另一个错误:

错误:模块 'app':未找到平台 'android-29'。

这可能是因为我已经下载了最新的Android版本,即Android R(在Android Studio中为Android 30),而这个项目可能期望的是版本29(Android Q)。因此,一旦我下载并安装了Android 29,方法是进入工具 -> SDK管理器,并重新启动Android Studio,它就可以正常工作,不再出现任何错误。

英文:

I checked the gradle sync inside Android Studio itself, and I found there was another error there:

ERROR: Module &#39;app&#39;: platform &#39;android-29&#39; not found.

This was probably because I had downloaded the latest Android version, which is Android R (aka Android 30 in Android Studio), while this project probably expected version 29 (Android Q). So, once I downloaded and installed Android 29, by going to Tools -> SDK Manager, and restarted Android Studio, it works fine and does not give any error.

答案2

得分: 0

sdkmanager需要JDK 8才能正常工作,特别是在运行--licenses选项时。它不需要是Oracle JDK,AdoptOpenJDK对我来说运行良好。

英文:

sdkmanager requires JDK 8 to work properly, especially when running the --licenses option. It doesn't need to be the oracle JDK, AdoptOpenJDK worked fine for me.

huangapple
  • 本文由 发表于 2020年8月13日 12:16:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63388055.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定