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

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

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

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


当前回答

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

这就是我遇到的问题:

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!

其他回答

如果你在应用中使用Leadbolt广告SDK,并将“通知广告”和“显示广告”结合在一起,你需要使用pubxappCom.jar而不是pubxapp.jar来发布通知广告,否则你就会出现这个错误!

编码快乐!

以前提出的解决方案对我都不起作用。以我为例,当我从引用库源代码文件夹切换到使用库JAR文件时,问题发生了。 最初,在Android应用程序项目属性\ Android页面\ library部分下列出了一个Android库项目,该库也在项目资源管理器树中作为库源目录的链接进行比较。

首先,我只是从项目树中删除了目录链接,并将JAR库添加到构建路径中,但这导致了异常。

正确的过程是(在更改回构建路径并将引用放回库源代码之后):

通过移除应用程序项目属性\ Android页面中的引用,正确地删除库源目录链接 像往常一样将库JAR添加到应用程序项目构建路径。

我使用adt7和其他修复没有工作(但我仍然做了他们)。

然后我复制了proguard.cfg从另一个项目,并简单地粘贴到旧的ADT项目文件夹。哇,成功了。

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

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

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

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