在Eclipse中的Android应用程序中,我得到了以下错误。

意想不到的顶级异常: java.lang.IllegalArgumentException:已添加:Lorg/xmlpull/v1/XmlPullParser; .... 转换到Dalvik格式失败,错误1

此错误仅在向项目添加特定的外部JAR文件时出现。我花了很长时间寻找可能的解决方案,但没有一个可行。

我甚至尝试将Android 1.6而不是1.5(我目前使用的版本)。


当前回答

这些答案对我都没用。我的问题是由JUnit和hamcrest引起的。参见java.lang.IllegalArgumentException: already added: Lorg/hamcrest/BaseDescription;转换到Dalvik格式失败,错误1

其他回答

我解决了这个问题。

这是一个JAR文件冲突。

我的构建路径上似乎有两个包含相同包和类的JAR文件。

jar和android_maps_lib-1.0.2

从一个JAR文件中删除这个包就解决了这个问题。

我也遇到过同样的问题,但这些方法都不起作用。 最后,我在控制台中看到错误是由于重复的类(一个在现有项目中,一个在添加的jar文件中):

java.lang.IllegalArgumentException: already added: package/MyClassclass;
[2011-01-19 14:54:05 - ...]: Dx1 error; aborting
[2011-01-19 14:54:05 - ...] Conversion to Dalvik format failed with error 1

因此,请检查您是否在项目中添加了带有重复类的jar。 如果是,请尝试移除其中一个。

这对我很管用。

此错误是由于

拥有多个JAR文件。 如果JAR文件具有类似的类文件,则不能解析.dx格式。

解决方案:

制作并选择适当的JAR文件。 买最新的。

我在其类路径中包含protobuf lite (Protocol Buffers by谷歌)的项目中有完全相同的错误。我想原因是我的类路径和项目文件夹中的protobuf-lite.jar是在我以前的机器中构建的。当我下载Maven并重新构建protobuf-lite.jar文件,然后将其作为用户库重新添加到我的项目中时,一切都很正常。

上面列出的解决方案没有一个对我有效。

这就是我遇到的问题:

I added the jSoup external JAR file to my project's path by first putting it in a source folder called "libs", and then right clicking on it, Build Path -> add to build path. This threw the Dalvik conversion error. It said I had "already included" a class from that JAR file. I looked around the project's directory and found that the place where it was "already included" was in fact the bin directory. I deleted the JAR file from the bin directory and refreshed the project in Eclipse and the error went away!