Where to put JAXB dependency for compiling Android Databinding on Java 11?

Moshe Katz

I am using Android Data Binding, and while things were simple it was working very well. However, once I added a BindingAdapter annotation, my project stopped building in Android Studio with an error Execution failed for task ':app:compileSaferesourceDebugJavaWithJavac', but it didn't give me any more detail. Running gradlew build on the command line showed that the actual error was java.lang.ClassNotFoundException: javax.xml.bind.JAXBException. This makes sense, because this development machine has only Java 11 installed, not Java 8.

I found this answer, which says to add the following dependencies to gradle:

implementation "javax.xml.bind:jaxb-api:2.2.11"
implementation "com.sun.xml.bind:jaxb-core:2.2.11"
implementation "com.sun.xml.bind:jaxb-impl:2.2.11"
implementation "javax.activation:activation:1.1.1"

The problem I have is that I don't know where to add them. Adding them as implementation dependencies to the app/build.gradle doesn't work, because JAXB is a dependency of the build tools, not of my application itself.

I tried adding them as buildscript.dependencies too, but that didn't work either:

buildscript {
    repositories {
        google()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath "javax.xml.bind:jaxb-api:2.3.1"
        classpath "com.sun.xml.bind:jaxb-core:2.3.0"
        classpath "com.sun.xml.bind:jaxb-impl:2.3.1"
        classpath "javax.activation:activation:1.1.1"
    }
}

I also tried adding them as buildscript.dependencies in the project root build.gradle file, but that also did not help:

buildscript {
    repositories {
        google()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath "javax.xml.bind:jaxb-api:2.3.1"
        classpath "com.sun.xml.bind:jaxb-core:2.3.0"
        classpath "com.sun.xml.bind:jaxb-impl:2.3.1"
        classpath "javax.activation:activation:1.1.1"
    }
}

I know that I can use Java 8 to build this code, but I really don't want to have to deal with multiple Java versions and I have other projects that require Java 11.

Is there a place in the gradle configuration that I can put these build dependencies to get them to work?


Configurations I tested:

  • Operating Systems: Tested on Windows 10 and Windows Server 2016
  • Build Environments: Tested in Android Studio 3.4.1, Android Studio 3.5.0-beta04, and using Gradle Wrapper on the command line
  • Android Gradle Plugin: tested with 3.4.1 and 3.5.0-beta04
  • Android Build Tools: tested with 28.0.3 and 29.0.0

Note: comment asks for Databinding version, which is no longer relevant since Databinding is now built-in and does not have a separate version number.

Fail with error show above:

  • Java 11.0.1 x64

Working properly:

  • Java 1.8.0_212 x64

After extensive testing, it is clear that the Java version is the only thing that makes any difference here.

Moshe Katz

UPDATE As of 2020-07-21, the Android bug tracker now states:

Studio will also start using JDK 11 starting in 4.2, approx in 1 to 2 months.


According to a member of the Android Project on the Android Bug Tracker as of 2019-03-07:

Java 11 is not supported by Android studio and its tools.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Where should I put -cp when compiling/running java files

Android DataBinding where to get context?

Java 11 issue with jaxb dependencies

Eclipse, Java 11, OSGI, and JAXB

Where to put Dependency Injection classes in clean architecture

Unresolved DataBinding dependency after latest Android Studio Update 3.3.2

Android/Gradle: Where is this dependency embedded?

WPF dependency property Databinding

JAXB / Java 11 / Tomcat - DataHandler No default constructor

Converting Android project with databinding from Java to Kotlin

Android Studio windows 11 - where is JAVA_HOME?

Disabling compile-time dependency checking when compiling Java classes

Java where to put private assets?

Where to put the 'return' keyword in java?

Where and how to put the package.json in a tgz dependency

Update firebase 11 dependency on Android Gradle

Not work: Android Studio 3.2 Canary11 + 3.2.0-alpha11 for kapt with com.android.databinding

Compiling a Gradle Java project with Java 8 but running tests with Java 11

Compatibility of Drools' dependency xstream and Java 11

Java 11 does not produce a .class file when compiling the class with 'java'

Where is "Control Center" in Java 11?

Android studio databinding error, Cannot find symbol: debug/dataBindingGenBaseClassesDebug/databinding/ActivitySignupBinding.java

Detox + android Compiling DetoxTest.java fails

Compiling Java 11 code with maven-compiler-pugin 2.2

JAXB ClassNotFoundException Building Spring Boot App 2.2.0 with Java 11

How can I import JAXB into a Java 11 IntelliJ (Gradle) project?

How to create POJO classes using JAXB maven plugin in java 11

Android: Where to put functions that multiple fragments share

Android: Where to put functions that multiple fragments share