在Java 11上将JAXB依赖关系放在哪里来编译Android数据绑定? [英] Where to put JAXB dependency for compiling Android Databinding on Java 11?

查看:329
本文介绍了在Java 11上将JAXB依赖关系放在哪里来编译Android数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android数据绑定,尽管事情很简单,但是运行得很好.但是,一旦添加 BindingAdapter 批注,我的项目就停止在Android中构建Studio出现错误Execution failed for task ':app:compileSaferesourceDebugJavaWithJavac',但没有提供更多详细信息.在命令行上运行gradlew build表示实际错误是java.lang.ClassNotFoundException: javax.xml.bind.JAXBException.这是有道理的,因为此开发计算机仅安装了Java 11,没有安装Java 8.

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.

我找到了此答案,它说要向gradle添加以下依赖项:

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"

我的问题是我不知道在哪里添加它们.将它们作为implementation依赖项添加到app/build.gradle无效,因为JAXB是构建工具的依赖关系,而不是我的应用程序本身的依赖关系.

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.

我也尝试将它们添加为buildscript.dependencies,但这也不起作用:

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"
    }
}

我还尝试将它们作为buildscript.dependencies添加到项目根build.gradle文件中,但这也无济于事:

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"
    }
}

我知道我可以使用Java 8来构建此代码,但是我真的不想处理多个Java版本,并且我有其他需要Java 11的项目.

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.

在gradle配置中是否可以放置这些构建依赖项以使其正常工作?

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

  • 操作系统:已在Windows 10和Windows Server 2016上进行测试
  • 构建环境:在Android Studio 3.4.1,Android Studio 3.5.0-beta04中进行了测试,并在命令行上使用了Gradle Wrapper
  • Android Gradle插件:已在3.4.1和3.5.0-beta04上进行测试
  • Android Build Tools:已通过28.0.3和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.

  • Java 11.0.1 x64
  • Java 1.8.0_212 x64

经过广泛的测试,很明显,Java版本是唯一在这里有所不同的东西.

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

推荐答案

更新截至2020-07-21,Android错误跟踪器

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

Studio还将在大约1到2个月内从4.2开始使用JDK 11.

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


根据Android项目在Android Bug Tracker上的成员 2019-03-07:


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

Android Studio及其工具不支持Java 11.

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

这篇关于在Java 11上将JAXB依赖关系放在哪里来编译Android数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆