gpt4 book ai didi

javax.xml.bind 在 Android Studio (Gradle) 中不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:01 26 4
gpt4 key购买 nike

我最近将我的 android 项目从 maven 迁移到 gradle。这样做之后,我无法在我的 java 文件中导入 javax.xml.bind。当项目在 maven 中时,这运行良好(可能是因为它是一个 java 项目而不是 android 项目)。

我在网上搜索,发现JVM 支持javax.xml.bind 但DVM(Dalvik Virtual Machine) 不支持。所以我尝试将这个库添加为我的 build.gradle 文件中的依赖项,如下所示:

dependencies {
....
compile 'javax.xml.bind:jaxb-api:2.2.x'
....
}

当我在上述更改后构建我的应用程序时,出现以下构建错误:

:dexDebug
Unknown source file : trouble processing "javax/xml/bind/annotation/XmlID.class":
Unknown source file : Ill-advised or mistaken usage of a core class (java.* or javax.*)
Unknown source file : when not building a core library.
Unknown source file : This is often due to inadvertently including a core library file
Unknown source file : in your application's project, when using an IDE (such as
Unknown source file : Eclipse). If you are sure you're not intentionally defining a
Unknown source file : core class, then this is the most likely explanation of what's
Unknown source file : going on.
Unknown source file : However, you might actually be trying to define a class in a core
Unknown source file : namespace, the source of which you may have taken, for example,
Unknown source file : from a non-Android virtual machine project. This will most
Unknown source file : assuredly not work. At a minimum, it jeopardizes the
Unknown source file : compatibility of your app with future versions of the platform.
Unknown source file : It is also often of questionable legality.
Unknown source file : If you really intend to build a core library -- which is only
Unknown source file : appropriate as part of creating a full virtual machine
Unknown source file : distribution, as opposed to compiling an application -- then use
Unknown source file : the "--core-library" option to suppress this error message.
Unknown source file : If you go ahead and use "--core-library" but are in fact
Unknown source file : building an application, then be forewarned that your application
Unknown source file : will still fail to build or run, at some point. Please be
Unknown source file : prepared for angry customers who find, for example, that your
Unknown source file : application ceases to function once they upgrade their operating
Unknown source file : system. You will be to blame for this problem.
Unknown source file : If you are legitimately using some code that happens to be in a
Unknown source file : core package, then the easiest safe alternative you have is to
Unknown source file : repackage that code. That is, move the classes in question into
Unknown source file : your own package namespace. This means that they will never be in
Unknown source file : conflict with core system classes. JarJar is a tool that may help
Unknown source file : you in this endeavor. If you find that you cannot do this, then
Unknown source file : that is an indication that the path you are on will ultimately
Unknown source file : lead to pain, suffering, grief, and lamentation.
Unknown source file : 1 error; aborting

:dexDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

如何成功导入这个库?我是 android 和 gradle 的初学者,所以任何帮助对我都有很大用处:)

最佳答案

看到你的项目正在导入核心类(java.* 或 javax.*)。

这里有一种方法,您可以使用“JarJar”工具将“javax.xml.bind”命名空间更改为另一个命名空间(例如:“oop.xml.bind”),这样您就可以解决这个问题并将其导入为 Third -Party库,你可以避免与核心类相同的命名空间。

祝你好运!

关于javax.xml.bind 在 Android Studio (Gradle) 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33890298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com