【发布时间】:2016-02-26 16:42:08
【问题描述】:
我最近将我的 android 项目从 maven 迁移到了 gradle。这样做之后,我无法在我的 java 文件中 import 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 的初学者,所以任何帮助对我都有很大用处:)
【问题讨论】:
-
@IntelliJAmiya 上面的链接是 maven 特定的,但我们使用的是 gradle。另外,这是一个 android 项目,所以它在 DVM 下。
-
好的设置
2.2.9而不是2.2.x -
@IntelliJAmiya 还是同样的错误
标签: java android xml android-gradle-plugin