麻烦处理“javax / xml / XMLConstants.class”

时间:2012-03-22 05:11:22

标签: java android

我正在开始一个新的Android项目。该项目引用了一个第三方JAR,后者又引用了其他4个罐子:

ws-commons-java5-1.0.1.jar
ws-commons-util-1.0.2.jar
xmlrpc-client-3.1.3.jar
xmlrpc-common-3.1.3.jar

据我所知,我认为这4个罐子是我认为的标准Java类。无论如何,我的Build Path中有五个这些罐子(上面的4个+ 1个第三方罐子)。当我尝试运行我的Android应用程序时,我得到:

Dx 
trouble processing "javax/xml/XMLConstants.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.

[2012-03-21 23:05:05 - MyApp ] Dx 1 error; aborting
[2012-03-21 23:05:05 - MyApp ] Conversion to Dalvik format failed with error 1

我不知道该怎么做。这就像是在问我是不是想要建立一个核心库,我不是。我只是想在我的项目中使用这些JAR。还有另一种方法我应该在我的项目中引用这些JAR吗?这个错误让我觉得我的项目有一天会随机停止为某人工作。

这一切都让人很困惑。关于如何正确进行的任何线索?

2 个答案:

答案 0 :(得分:1)

在SO上有一些类似的问题报告(与其他类但是相同类型的消息)并且隐藏在closed question的一条评论中我找到了指向外部站点上的解决方案的指针:

Ill-advised or mistaken usage of a core class

答案 1 :(得分:0)

你的问题是ws-commons-java5-1.0.1.jar是核心Java库的一部分的重新实现。 Android不允许您替换核心库。

好消息是ws-commons-java5只应该是java 1.4或更低版本所必需的,Android包含它取代的java 1.5中的类。因此,您应该只能从项目中删除此文件,它应该可以正常工作...