在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(我目前使用的版本)。
当前回答
我遇到了这个问题,因为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>
其他回答
对于仍然有这个问题的其他人,他们尝试了上面的答案但仍然得到错误(这是我的情况),那么我的解决方案是从Eclipse中删除项目并重新导入它。
这使得Android库再次添加到我的引用库中,所以现在我有两个Android JAR文件引用,因此我删除了其中一个,现在它编译良好。
解决方案:从Eclipse IDE中删除项目,然后重新导入,然后检查上述解决方案。
这种情况通常发生在eclipse运行了很长时间之后,或者在我成功地构建了一个带签名的apk之后。
就我的经验而言,修复它我只是重新启动eclipse。
我在其类路径中包含protobuf lite (Protocol Buffers by谷歌)的项目中有完全相同的错误。我想原因是我的类路径和项目文件夹中的protobuf-lite.jar是在我以前的机器中构建的。当我下载Maven并重新构建protobuf-lite.jar文件,然后将其作为用户库重新添加到我的项目中时,一切都很正常。
今天我自己也遇到了这个问题。清理和重建并没有解决问题。删除和重新导入项目也没有帮助。
我最终追踪到我的.class文件中的一个坏添加。我认为这是由插件工具添加的,当我试图解决另一个问题时,删除它摆脱了“转换到Dalvik格式失败,错误1”的构建错误:
<classpathentry kind="lib" path="C:/dev/repository/android-sdk-windows/platforms/android-3/android.jar">
<attributes>
<attribute name="javadoc_location" value="file:/C:/dev/repository/android-sdk-windows/docs/reference"/>
</attributes>
<accessrules>
<accessrule kind="nonaccessible" pattern="com/android/internal/**"/>
</accessrules>
在我的案例中,这个问题起源于2011年3月更新Eclipse和ADT之后。在我的项目中,我正在使用一个JAR,它正在产生问题来重建,以前的解决方案都不起作用。我花了好几天的时间,到处找都没有满意的答案。显然,.jar文件有双重引用。
最后我:
从库中删除了所有引用, 删除应用程序中的物理文件表单。 使用“添加外部jar”获得。jar(位于项目外部的另一个目录) 执行项目“清洁”, 用(ctrl)+(shift)+O将引用更新到调用jar的模块中
它终于编译成功了。