Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Java 11 gives TaskExecutionException in Android Studio?

So, I'm working on one large existing company project, where things are old / deprecated and I'm trying to improve it step by step.

Right now I'm trying to update JDK version from Java 1.8 to Java 11. So I made changes from Android Studio preference settings.

Also I made this changes as well: https://developer.android.com/studio/releases/gradle-plugin#java-11

About my project:

targetSDKVersion: 30

Android Studio: Latest stable release

Project codeing: 50% code Java and 50% code Kotlin

So, when I made above 2 change and sync the project, it got successfully sync and when I try to run this this exception is coming.

java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137)
    at java.base/java.lang.Class.getConstructor0(Class.java:3342)
    at java.base/java.lang.Class.newInstance(Class.java:556)

Execution failed for task ':app:kaptPlaystoreDebugKotlin'.
> Internal compiler error. See log for more details

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptPlaystoreDebugKotlin'

NOTE: playstoreDebug is a build variant name.


1 Answers

Answer: Upon upgrading from java8 to java11 there are some libraries that have been removed. If one wants to use them they need to be specifically added as dependencies.

This question has already been answered:

javax.xml.bind.JAXBException Implementation of JAXB-API has not been found on module path or classpath

Replacements for deprecated JPMS modules with Java EE APIs

Add these dependencies into your pom/gradle:

Gradle:

compile('javax.xml.bind:jaxb-api:2.3.0')
compile('javax.activation:activation:1.1')
compile('org.glassfish.jaxb:jaxb-runtime:2.3.0')

Pom:

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0-b170201.1204</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.activation/activation -->
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.0-b170127.1453</version>
</dependency>
like image 200
Alex Avatar answered Dec 08 '25 18:12

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!