[英]java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException after updating to Android Studio 4.2
Google just release Android Studio 4.2 stable.谷歌刚刚发布了 Android Studio 4.2 稳定版。 I updated my AS from 4.1 to 4.2.我将我的 AS 从 4.1 更新到 4.2。 Now I am getting this error.现在我收到了这个错误。 It's showing error in data binding.它在数据绑定中显示错误。
Caused by: java.util.ServiceConfigurationError: javax.annotation.processing.Processor: android.databinding.annotationprocessor.ProcessDataBinding Unable to get public no-arg constructor
at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1200)
at kotlin.collections.CollectionsKt___CollectionsKt.toMutableList(_Collections.kt:1233)
at kotlin.collections.CollectionsKt___CollectionsKt.toList(_Collections.kt:1224)
at org.jetbrains.kotlin.kapt3.base.ProcessorLoader.doLoadProcessors(ProcessorLoader.kt:80)
at org.jetbrains.kotlin.kapt3.base.ProcessorLoader.loadProcessors(ProcessorLoader.kt:45)
at org.jetbrains.kotlin.kapt3.base.Kapt.kapt(Kapt.kt:42)
... 28 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
... 34 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
... 34 more
Android Studio 4.2.0 and more now comes with Java 11.0.8 shipped and will use it by default which cases this error in deprecated libraries. Android Studio 4.2.0和更多现在随附 Java 11.0.8 ,默认情况下将使用它,这会在已弃用的库中出现此错误。
The solution is simple, you need to change it to java (JDK) 1.8 in the menu File > Project Structure > JDK Location
解决方法很简单,需要在菜单File > Project Structure > JDK Location
中将其更改为java (JDK) 1.8
Notices that Android Studio lower than 4.2.0 comes with java 1.8 already注意 Android Studio 低于 4.2.0 已经带有 java 1.8
By doing the following steps I solved this problem without replacing JDK with JAVA 8.通过执行以下步骤,我解决了这个问题,而没有用 JAVA 8 替换 JDK。
Step 1: Update the distributionUrl
to https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
in your gradle-wrapper.properties
第 1 步:在gradle-wrapper.properties
distributionUrl
更新为https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
Step 2: Update your gradle tool classpath to 'com.android.tools.build:gradle:4.2.1'
in your root buid.gradle
Step 2: Update your gradle tool classpath to 'com.android.tools.build:gradle:4.2.1'
in your root buid.gradle
I had same issue, and I alrady solved.我有同样的问题,我已经解决了。 I found that Android studio 4.2 will make the JDK update to Java11, it will cause error what you described.我发现 Android studio 4.2 会使 JDK 更新到 Java11,它会导致你描述的错误。
You can delete the Java11 JDK and replace by Java8 (/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home).您可以删除 Java11 JDK 并替换为 Java8 (/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home)。
Also you can uninstall the Android Studio, and reinstall it.您也可以卸载 Android Studio,然后重新安装。
If you are using Ubuntu then just change the JDK location to JAVA (JDK) 1.8 in the menu File > Project Structure > JDK Location如果您使用的是 Ubuntu,那么只需在菜单 File > Project Structure > JDK Location 中将 JDK 位置更改为 JAVA (JDK) 1.8
I thought it was the jdk route, after hours searching, this worked for me我以为是jdk路线,经过几个小时的搜索,这对我有用
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
in your build.gradle file add and update kotlin_version在您的 build.gradle 文件中添加和更新 kotlin_version
ext.kotlin_version = '1.4.32'
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
}
if you use enableAapt2 remove it from your gradle.properties file如果您使用 enableAapt2 将其从 gradle.properties 文件中删除
org.gradle.jvmargs=-Xmx1536M -Dkotlin.daemon.jvm.options\="-Xmx1536M"
#android.enableAapt2=false
android.useAndroidX=true
android.enableJetifier=true
there are two method to solve this problem有两种方法可以解决这个问题
android {
packagingOptions {
exclude 'AndroidManifest.xml'
}
}
If you are coming here having Android Studio Arctic Fox which comes by default with Java 11, you need to use java 1.8 to find necessary classes which are completely removed in java 11 upgrade. If you are coming here having Android Studio Arctic Fox which comes by default with Java 11, you need to use java 1.8 to find necessary classes which are completely removed in java 11 upgrade.
Path to set in Android Studio Arctic Fox is as follows在Android Studio北极狐中设置的路径如下
Preferences > Build execution Deployment > Gradle > Gradle Sdk首选项 > 构建执行部署 > Gradle > Gradle Sdk
Choose Download JDK then Java 1.8.x version and rebuild the project.选择下载 JDK,然后选择 Java 1.8.x 版本并重建项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.