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

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

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

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


当前回答

我知道这个问题已经有答案了,但这是我的解决方案:

我的Android项目来自一个Subversion存储库,我刚刚做了Checkout as a New project。我必须手动将我的库(Android和Java)添加到构建路径,否则它不会让我编译。然后我就会得到上面的错误。

我必须创建一个新的Android项目,然后手动复制更改。

其他回答

我使用的是安卓1.6,有一个外部JAR文件。对我有用的是删除所有库,右键单击项目并选择Android Tools -> *Fix项目属性(添加回Android 1.6),然后添加回外部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>

对于仍然有这个问题的其他人,他们尝试了上面的答案但仍然得到错误(这是我的情况),那么我的解决方案是从Eclipse中删除项目并重新导入它。

这使得Android库再次添加到我的引用库中,所以现在我有两个Android JAR文件引用,因此我删除了其中一个,现在它编译良好。

解决方案:从Eclipse IDE中删除项目,然后重新导入,然后检查上述解决方案。

如果您在构建路径中添加了Android.jar文件,可能是由于Eclipse中的意外快速修复,也会导致这种情况。删除它右击项目->构建路径->配置构建路径-> android.jar,删除。

如果你想解决这个问题,那么你必须把Android SDK1.6换成Android 2.2。之后,清理项目,然后构建并运行。然后您将看到您的应用程序正在运行。