3

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 Answers1

3

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>
Alex
  • 66
  • 3
  • Hi Alex, Thanks for the answer. So I checked that answers which mentioned, that as well. Can you tell me which libraries that have been removed? And is this happening because I'm using maven {} in my project inside build.gradle (project) that's why? –  Sep 28 '21 at 13:38
  • These are the libraries that you should look out for moving to Java11: java.activation with javax.activation package java.corba with javax.activity, javax.rmi, javax.rmi.CORBA, and org.omg.* packages java.transaction with javax.transaction package java.xml.bind with all javax.xml.bind.* packages java.xml.ws with javax.jws, javax.jws.soap, javax.xml.soap, and all javax.xml.ws.* packages java.xml.ws.annotation with javax.annotation package – Alex Sep 28 '21 at 17:31
  • I am not familiar with your project setup, but if you add the missing dependencies then that should resolve your jaxb problem. – Alex Sep 28 '21 at 17:33
  • So Alex, I tried to search what is pom.xml file and people are suggesting that I should manually create pom.xml file in Android Studio, but when I created inside app level, I'm getting same errors. Can you guide me where should I place that pom.xml file, and I exactly copied this content what you shared, there is no other code in that file, so is that fine? –  Sep 29 '21 at 06:43
  • @SychiSingh You have a graddle error so it seems that you should use the graddle syntax only , not maven(it's your building engine, you have one or the other, not the both) – pdem Sep 29 '21 at 15:01
  • Agree with pdem to stick with the build system that you have, which appears to be gradle. Then you do not need to introduce Maven. – Alex Sep 29 '21 at 19:10
  • A clean project build might fix it. – Eyosiyas Sep 30 '21 at 04:32
  • @Eyosiyas Many times I tried, but that's not working –  Sep 30 '21 at 06:26
  • @Alex Hi Alex, so what should I do? –  Sep 30 '21 at 06:27
  • @pdem Ok, so what changes are necessary? –  Sep 30 '21 at 06:27
  • 1
    The JAXB APIs are removed from Java 11. Check this answer https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception – Eyosiyas Sep 30 '21 at 09:56
  • @Eyosiyas So do I make change of that which is suggested in answer or not? –  Oct 04 '21 at 05:18
  • Check it if it works with your project. – Eyosiyas Oct 04 '21 at 05:58
  • @Eyosiyas I'm not sure abt pom.xml file, how to create and where to put? –  Oct 04 '21 at 15:47
  • In Android studio, you don't need a pom.xml because Android Studio uses Gradle as the build system and not Maven. – JustinW Oct 05 '21 at 03:26
  • A summary of this discussion: First, use Gradle, not Maven as Gradle is the default building system for android. Second, add the dependencies mentioned by the author of this answer. Third, if you want to continue this discussion, stackoverflow chat is recommended, because it's going too long. – JustinW Oct 05 '21 at 03:29
  • @JustInCoding How can I use gradle? –  Oct 06 '21 at 09:40
  • Create a new Android Project in Android Studio, and then replace its app\src folder with the one in your maven project – JustinW Oct 06 '21 at 10:14