在Eclipse中的Android应用程序中,我得到了以下错误。
意想不到的顶级异常: java.lang.IllegalArgumentException:已添加:Lorg/xmlpull/v1/XmlPullParser; .... 转换到Dalvik格式失败,错误1
此错误仅在向项目添加特定的外部JAR文件时出现。我花了很长时间寻找可能的解决方案,但没有一个可行。
我甚至尝试将Android 1.6而不是1.5(我目前使用的版本)。
在Eclipse中的Android应用程序中,我得到了以下错误。
意想不到的顶级异常: java.lang.IllegalArgumentException:已添加:Lorg/xmlpull/v1/XmlPullParser; .... 转换到Dalvik格式失败,错误1
此错误仅在向项目添加特定的外部JAR文件时出现。我花了很长时间寻找可能的解决方案,但没有一个可行。
我甚至尝试将Android 1.6而不是1.5(我目前使用的版本)。
当前回答
我在其类路径中包含protobuf lite (Protocol Buffers by谷歌)的项目中有完全相同的错误。我想原因是我的类路径和项目文件夹中的protobuf-lite.jar是在我以前的机器中构建的。当我下载Maven并重新构建protobuf-lite.jar文件,然后将其作为用户库重新添加到我的项目中时,一切都很正常。
其他回答
我遇到了这个问题,因为Eclipse中的Android- maven -插件显然不能识别传递引用,并且从两个项目(包括一个Android库项目)中引用了两次引用,并且不止一次地包含它们。我不得不使用魔术使所有内容只包含一次,即使Maven应该处理所有这些。
例如,我有一个核心库globalmentor-core,它也被globalmentor-google和globalmentor-android使用(后者是一个Android库)。在globalmentor-android pom.xml中,我必须将依赖标记为“提供的”,并将其从其他库中排除。
<dependency>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-core</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- android-maven-plugin can't seem to automatically keep this from being
included twice; it must therefore be included manually (either explicitly
or transitively) in dependent projects -->
<scope>provided</scope>
</dependency>
然后在最后的应用程序pom.xml中,我必须使用正确的技巧,只允许一个包含路径——以及不显式地包括核心库:
<!-- android-maven-plugin can't seem to automatically keep this from being
included twice -->
<!-- <dependency> -->
<!-- <groupId>com.globalmentor</groupId> -->
<!-- <artifactId>globalmentor-core</artifactId> -->
<!-- <version>1.0-SNAPSHOT</version> -->
<!-- </dependency> -->
<dependency>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-google</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<!-- android-maven-plugin can't seem to automatically keep this from
being included twice -->
<exclusion>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-android</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
我也遇到过同样的问题,但这些方法都不起作用。 最后,我在控制台中看到错误是由于重复的类(一个在现有项目中,一个在添加的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文件包含在项目文件夹树的“lib”目录中。这样,您就不需要通过转到项目的属性来定义构建路径。"lib"已经是一个构建路径
在我的案例中,问题在于OpenFeint API项目。我添加了OpenFeint作为库项目:
.
它也被添加到构建路径中,ADT tools 16在此场景中给出错误。
右键单击你的项目,单击构建路径,配置构建路径,然后看到图像,并从这里删除你的项目OpenFeint,一切都完成了:)
没有什么能帮到我,但这里建议的解决方案非常有效:
例如,将-optimizations !code/allocation/variable添加到proguard-project.txt中