java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException after updating to Android Studio 4.2
Asked Answered
K

7

26

Google just release Android Studio 4.2 stable. I updated my AS from 4.1 to 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
Keavy answered 6/5, 2021 at 2:7 Comment(0)
L
54

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.

The solution is simple, you need to change it to java (JDK) 1.8 in the menu File > Project Structure > JDK Location

image

Notices that Android Studio lower than 4.2.0 comes with java 1.8 already

Lurdan answered 7/5, 2021 at 23:59 Comment(3)
I am not able to set JDK8 in menu: "Please choose a valid JDK 11 directory"Felicio
EDIT: after providing correct JDK location, it finally accepted. Just another misleading pop-up in Android Studio.Felicio
@Felicio I also get this notice "Please choose a valid JDK 11 directory"Hubing
S
21

By doing the following steps I solved this problem without replacing JDK with JAVA 8.

Step 1 : Update the distributionUrl to https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip in your gradle-wrapper.properties

Step 2: Update your gradle tool classpath to 'com.android.tools.build:gradle:4.2.1' in your root buid.gradle

Seduce answered 22/6, 2021 at 9:32 Comment(0)
S
8

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.

You can delete the Java11 JDK and replace by Java8 (/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home).

Also you can uninstall the Android Studio, and reinstall it.

Starrstarred answered 6/5, 2021 at 3:58 Comment(1)
I cannot find similar path in ubuntu. Can you help?Defoe
S
7

If you are using Ubuntu then just change the JDK location to JAVA (JDK) 1.8 in the menu File > Project Structure > JDK Location

JDK location android studio 4.2

Stipule answered 12/5, 2021 at 8:41 Comment(0)
E
5

I thought it was the jdk route, after hours searching, this worked for me

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

in your build.gradle file add and update 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

org.gradle.jvmargs=-Xmx1536M -Dkotlin.daemon.jvm.options\="-Xmx1536M"
#android.enableAapt2=false
android.useAndroidX=true
android.enableJetifier=true
Etzel answered 25/5, 2021 at 3:1 Comment(0)
B
4

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

Preferences > Build execution Deployment > Gradle > Gradle Sdk

Choose Download JDK then Java 1.8.x version and rebuild the project.

Becka answered 1/10, 2021 at 5:23 Comment(0)
E
1

there are two method to solve this problem

  1. roll back to Java 8
  2. update gradle tools 'com.android.tools.build:gradle' like 4.2.1(I used) maybe you will encounter "Entry name 'AndroidManifest.xml' collided" problem, add below to you App build.gradle
android {
    packagingOptions {
        exclude 'AndroidManifest.xml'
    }
}
Ephemeron answered 16/6, 2021 at 7:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.