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

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

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

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


当前回答

这个错误是由于我从构建路径中排除的几个文件被删除了,但没有从排除列表中删除。

项目->属性-> Java Build Path -> Source选项卡->项目/src文件夹->双击排除->删除项目中不再存在的任何文件。

其他回答

我遇到了这个问题,因为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>

今天我自己也遇到了这个问题。清理和重建并没有解决问题。删除和重新导入项目也没有帮助。

我最终追踪到我的.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>

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

以前我有Android SDK构建工具18.1.1和Windows XP。然后我的应用程序就正常运行了。

但是我把我的系统更新到Windows 7,还把Android SDK构建工具更新到19,以拥有最新的配置。

但是我的项目有xercesImpl-2.9.1.jar文件,所以当我开始运行我的应用程序与新的/更新的配置,我得到

Conversion to Dalvik format failed with error 1 while parsing org/apache/xerces/impl/xpath/regex/ParserForXMLSchema.class

所以我遍历了所有提到的这个问题的答案,但无法解决。我想了4天,然后我发现了这个链接,救了我的命,读了这篇文章后,我才知道这个问题是由于xercesimpll -2.9.1.jar与Android SDK构建工具到19。

所以我把它降级为Android SDK Build tools到18.1.1。我解决了这个问题。

我把我的答案贴在这里,这样如果有人遇到这个问题,他们就能解决它。

这让我很沮丧。希望能帮助别人。

依赖项上的谷歌API会导致此问题。拆卸后工作良好。