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

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

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

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


当前回答

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

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

其他回答

这些答案对我都没用。我的问题是由JUnit和hamcrest引起的。参见java.lang.IllegalArgumentException: already added: Lorg/hamcrest/BaseDescription;转换到Dalvik格式失败,错误1

每次出现这种错误时,简单地清理项目对我来说都很有效。

我还发现了别的东西。Android使用/libs目录存放JAR文件。我曾多次看到“转换到Dalvik格式失败,错误1”的错误,总是在我的JAR文件中出错时出现。

现在我将Roboguice升级到一个新版本,方法是将新的JAR文件放在/libs目录中,并将类路径切换到新版本。这导致了Dalvik错误。

当我从/libs文件夹中删除一个Roboguice JAR文件时,错误消失了。显然,Android会从/libs中获取所有JAR文件,而不管您在Java构建路径中指定了哪些文件。我不太记得了,但我认为Android从Android 4.0 (Ice Cream Sandwich, ICS)开始默认使用/libs。

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

我遇到了这个问题,但我的解决办法是双重的。 1)。我不得不在项目->属性-> Android下添加一个Android目标版本。 2)。我没有所有的“第三方插件”。点击AVD SDK管理器下的可用软件包->第三方附加组件->谷歌公司。我下载了所有的sdk,这解决了我的问题。