简体   繁体   English

外部 JAR 上的“转换为 Dalvik 格式失败,错误 1”

[英]“Conversion to Dalvik format failed with error 1” on external JAR

In my Android application in Eclipse I get the following error.在 Eclipse 中的 Android 应用程序中,我收到以下错误。

UNEXPECTED TOP-LEVEL EXCEPTION:意外的顶级例外:
java.lang.IllegalArgumentException: already added: Lorg/xmlpull/v1/XmlPullParser; java.lang.IllegalArgumentException:已添加:Lorg/xmlpull/v1/XmlPullParser;
.... ....
Conversion to Dalvik format failed with error 1转换为 Dalvik 格式失败,错误 1

This error only appears when I add a specific external JAR file to my project.仅当我将特定的外部 JAR 文件添加到我的项目时才会出现此错误。 I searched for a long time for the possible solution, but none of the possible solutions work.我搜索了很长时间以寻找可能的解决方案,但没有一个可能的解决方案有效。

I even tried to change to Android 1.6 instead of 1.5 (the current version I use).我什至尝试更改为 Android 1.6 而不是 1.5(我使用的当前版本)。

Go to Project » Properties » Java Build Path » Libraries and remove all except the "Android XY" (in my case Android 1.5).转到 Project » Properties » Java Build Path » Libraries 并删除除“Android XY”之外的所有内容(在我的情况下为 Android 1.5)。 click OK.单击确定。 Go to Project » Clean » Clean projects selected below » select your project and click OK.转到项目»清理»清理下面选择的项目»选择您的项目并单击确定。 That should work.那应该工作。

It is also possible that you have a JAR file located somewhere in your project folders (I had copied the Admob JAR file into my src folder) and THEN added it as a Java Path Library.也有可能您的项目文件夹中的某个位置有一个 JAR 文件(我已将 Admob JAR 文件复制到我的 src 文件夹中),然后将其添加为 Java 路径库。 It does not show up under the Package Explorer, so you don't notice it, but it does get counted twice, causing the dreaded Dalvik error 1.它没有出现在包资源管理器下,所以你不会注意到它,但它确实被计数了两次,导致可怕的 Dalvik 错误 1。

Another possible reason could be package name conflicts.另一个可能的原因可能是包名冲突。 Suppose you have a package com.abc.xyz and a class named A.java inside this package, and another library project (which is added to the dependency of this project) which contains the same com.abc.xyz.A.java , then you will be getting the exact same error.假设你在这个包中有一个包com.abc.xyz和一个名为A.java的类,以及另一个包含相同com.abc.xyz.A.java库项目(它被添加到这个项目的依赖项中),那么你会得到完全相同的错误。 This means, you have multiple references to the same file A.java and can't properly build it.这意味着,您对同一个文件A.java有多个引用,并且无法正确构建它。

In other ways this may be occurred if you accidentally or knowingly edit/ add any thing in the class path file manually .In certain cases we may add android.jar path manually to classpath file for generating java doc.On removing the that after javadoc generated code will works fine.Please check this too if any one still occurs.在其他情况下,如果您不小心或故意在类路径文件中手动编辑/添加任何内容,可能会发生这种情况。在某些情况下,我们可能会手动将 android.jar 路径添加到类路径文件中以生成 java doc。在生成 javadoc 后删除该路径代码将正常工作。如果仍然出现任何问题,请检查此内容。

I solved the problem.我解决了这个问题。

This is a JAR file conflict.这是 JAR 文件冲突。

It seems that I have two JAR files on my buildpath that include the same package and classes.我的构建路径上似乎有两个 JAR 文件,其中包含相同的包和类。

smack.jar and android_maps_lib-1.0.2 smack.jarandroid_maps_lib-1.0.2

Deleting this package from one of the JAR files solved the problem.从其中一个 JAR 文件中删除这个包解决了这个问题。

Windows 7 Solution: Windows 7 解决方案:

Confirmed the problem is caused by ProGuard command line in the file确认问题是由文件中的 ProGuard 命令行引起的
[Android SDK Installation Directory]\\tools\\proguard\\bin\\proguard.bat 【Android SDK安装目录】\\tools\\proguard\\bin\\proguard.bat

Edit the following line will solve the problem:编辑以下行将解决问题:

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*

to

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9

You can solve this issue easily (with Eclipse Android Developer Tools, Build: v22.0.1-685705) by turn off menu > "Project" > "Build Automatically" while exporting (un)signed Android application.您可以通过在导出(未)签名的 Android 应用程序时关闭菜单 >“项目”>“自动构建”来轻松解决此问题(使用 Eclipse Android 开发者工具,构建:v22.0.1-685705)。 After that, don't forget to turn it on again.之后,不要忘记再次打开它。

If you have ADT revision 12+, you should update your proguard from 4.4 -> 4.6 (as described here ).如果你有ADT修订12+,你应该从4.4更新您的ProGuard - > 4.6(描述在这里)。 Also, you should leave ...\\bin\\proguard.bat file in the orginal form.此外,您应该保留原始格式的 ...\\bin\\proguard.bat 文件。

Just download it from the web, and copy lib folder from downloaded package to the :只需从网上下载它,然后将下载的包中的 lib 文件夹复制到:

[Android SDK Installation Directory]\\tools\\proguard\\lib 【Android SDK安装目录】\\tools\\proguard\\lib

EDIT (new solution):编辑(新解决方案):

It looks like the previous solution is only a bypass.看起来以前的解决方案只是一个旁路。 I managed to finally fix the problem permanently: In my case there was a mismatch in android-support-v4 files in my project and in the Facebook project that is referenced in my project.我最终设法永久解决了这个问题:就我而言,我的项目和我的项目中引用的 Facebook 项目中的 android-support-v4 文件不匹配。

I found this error by performing Lint Check (Android Tools / Run Lint: Check for Common Errors)我通过执行 Lint 检查发现了这个错误(Android 工具/运行 Lint:检查常见错误)

My previous solution:我以前的解决方案:

I've tried any possible solution on this site - nothing helped!!!我已经在这个网站上尝试了任何可能的解决方案 - 没有任何帮助!!!

Finally I've found an answer here: https://groups.google.com/forum/#!topic/actionbarsherlock/drzI7pEvKd4最后我在这里找到了答案: https : //groups.google.com/forum/#!topic/actionbarsherlock/drzI7pEvKd4

Easy steps:简单的步骤:

Go to Project -> uncheck Build Automatically转到项目-> 取消选中自动构建

Go to Project -> Clean... , clean both the library project and your app project转到 Project -> Clean... ,同时清理库项目和您的应用项目

Export your app as a signed APK while Build Automatically is still disabled将您的应用导出为已签名的 APK,而“自动构建”仍处于禁用状态

Here's another scenario, and solution:这是另一个场景和解决方案:

If you run into this problem recently after updating the ADT for Eclipse:如果您最近在为 Eclipse 更新 ADT 后遇到此问题:

  1. In your app project, check for any linked source folders pointing to your library projects (they have names in the form "LibraryName_src").在您的应用项目中,检查是否有任何指向您的库项目的链接源文件夹(它们的名称为“LibraryName_src”形式)。
  2. Select all those projects, right-click, choose " Build Path "->" Remove from Build Path ".选择所有这些项目,右键单击,选择“构建路径”->“从构建路径中删除”。
  3. Choose " Also unlink the folder from the project ", and click " Yes ".选择“同时取消文件夹与项目的链接”,然后单击“”。
  4. Clean, rebuild and redeploy the project.清理、重建和重新部署项目。

It seems the reason is that some previous version of ADT linked Library project source folders to the "child" projects, and the current ADT/Dex combination isn't compatible with that solution anymore.原因似乎是某些先前版本的 ADT 将库项目源文件夹链接到“子”项目,而当前的 ADT/Dex 组合不再与该解决方案兼容。

EDIT: this is confirmed by an Android Dev Blog entry, specifically this one - see the 8th paragraph onwards.编辑:这是由一个 Android 开发博客条目确认的,特别是这个- 请参阅第 8 段以后。

转到项目,然后取消选中“自动构建”。然后尝试导出项目,错误消失了。

This can also be caused if you have added Android.jar file to your build path, perhaps by an accidental quick fix in Eclipse.如果您已将Android.jar文件添加到您的构建路径,这也可能是由于 Eclipse 中的意外快速修复造成的。 Remove it with right clicking Project -> build path -> configure build path -> android.jar , remove.右键单击Project -> build path -> configure build path -> android.jar删除它,删除。

每次出现此错误时,简单地清理项目对我都有效。

My own and only solution that I found today after four hours of testing all the solutions, is a combination of many solutions provided here:在对所有解决方案进行四个小时的测试后,我今天找到的唯一的解决方案是这里提供的许多解决方案的组合:

  • Delete project from Eclipse从 Eclipse 中Delete项目
  • Delete files in \\bin and \\gen from project folder从项目文件夹中删除\\bin\\gen文件
  • Remove references to libraries into .classpath file in root project folder将库的引用删除到根项目文件夹中的.classpath文件中
  • Restart Eclipse with command line : eclipse -clean使用命令行重新启动 Eclipse: eclipse -clean
  • Import project Import项目
  • Right click on project - select Properties > Java Build Path > Libraries and remove everything else than Android XX.Y右键单击项目 - 选择Properties > Java Build Path > Libraries并删除除Android XX.Y之外的所有内容
  • Finally clean project, wait for automatic Building or Build it最后clean项目,等待自动构建或Build
  • Launch and now it works!启动,现在它可以工作了! At least for me...至少对于我来说...

I tried every step at a time and many combinations, but only the succession of all steps at once made it!我一次尝试了每一步和许多组合,但只有一次连续所有步骤才能成功! I hope I won't face this again...我希望我不会再遇到这种情况......

Just for the other people who still have this problem and they have tried the above answers but still getting the error (which was my case), then my solution was to delete the project from Eclipse and re-import it again.仅对于仍然存在此问题的其他人并且他们已经尝试了上述答案但仍然出现错误(这是我的情况),然后我的解决方案是从 Eclipse 中删除该项目并再次重新导入它。

This made the Android library to be added again to my referenced libraries, so now I have two Android JAR files referenced, hence I deleted one of them and now it compiles fine.这使得 Android 库再次添加到我引用的库中,所以现在我引用了两个 Android JAR 文件,因此我删除了其中一个,现在它可以正常编译。

Solution: Delete the project from Eclipse IDE and then re-import it again, then check for the above solutions.解决方案:从Eclipse IDE中删除项目,然后重新导入,然后查看上述解决方案。

Ran into this problem myself today.今天自己遇到了这个问题。 Cleaning and rebuild did not fix the problem.清洁和重建没有解决问题。 Deleting and reimporting the project didn't help either.删除并重新导入项目也无济于事。

I finally traced it back to a bad additions to my .class file.我终于将其追溯到我的 .class 文件中的一个错误添加。 I think this was added by the plugin tools when I was trying to fix another problem, removing it got rid of the "Conversion to Dalvik format failed with error 1" build error:我认为这是在我尝试解决另一个问题时由插件工具添加的,删除它可以消除“转换为 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>

For me, an extra JAR reference had appeared in my build path.对我来说,我的构建路径中出现了一个额外的 JAR 引用。 I deleted this, and it works now.我删除了它,现在可以使用了。

I've dealt with this problem when using Sherlock ActionBar library in my project.我在我的项目中使用 Sherlock ActionBar 库时处理过这个问题。 You could do the following step, it's work for me.您可以执行以下步骤,这对我有用。

  1. Right click to your project, select properties.右键单击您的项目,选择属性。
  2. A dialog will show up, select 'Java build path' on the left menu.将出现一个对话框,在左侧菜单中选择“Java 构建路径”。
  3. Remove 'Android dependencies' and 'Android private libraries' on the right panel then click OK删除右侧面板上的“Android 依赖项”和“Android 私有库”,然后单击“确定”
  4. Clean your project (select menu Project --> Clean)清理您的项目(选择菜单 Project --> Clean)
  5. Right click your project, select Android Tools -> Fix project properties右键单击您的项目,选择 Android 工具 -> 修复项目属性
  6. Clean project once again.再次清理项目。
  7. Restart your computer重启你的电脑
  8. Open eclipse and Export apk打开eclipse并导出apk

Hope that will help you.希望这会帮助你。

My problem was caused by ADT version 12.0 and ProGuard integration.我的问题是由 ADT 12.0 版和 ProGuard 集成引起的。 This bug is well documented and the solution is in the documentation这个错误有据可查,解决方案在文档中

Solution is in here解决方案在这里

ProGuard command line ProGuard 命令行

I found something else.我发现了别的东西。 Android uses the /libs directory for JAR files. Android 将/libs目录用于 JAR 文件。 I have seen the "Conversion to Dalvik format failed with error 1" error numerous times, always when I made a mistake in my JAR files.我已经多次看到“Conversion to Dalvik format failed with error 1”错误,总是当我在 JAR 文件中出错时。

Now I upgraded Roboguice to a newer version, by putting the new JAR file in the /libs directory and switching the class path to the new version.现在我将 Roboguice 升级到新版本,将新的 JAR 文件放在/libs目录中并将类路径切换到新版本。 That caused the Dalvik error.这导致了 Dalvik 错误。

When I removed one of the Roboguice JAR files from the /libs folder, the error disappeared.当我从/libs文件夹中删除 Roboguice JAR 文件之一时,错误消失了。 Apparently, Android picks up all JAR files from /libs , regardless of which ones you specify in the Java build path.显然,Android 会从/libs提取所有 JAR 文件,无论您在 Java 构建路径中指定了哪些文件。 I don't remember exactly, but I think Android started using /libs by default starting with Android 4.0 (Ice Cream Sandwich, ICS).我记不太清楚了,但我认为 Android 默认从Android 4.0 (Ice Cream Sandwich,ICS)开始使用/libs

In general, it seems that this problem comes when there are unnecessary JAR files in build path.一般来说,这个问题似乎是在构建路径中有不必要的 JAR 文件时出现的。

I faced this problem while working on IntelliJ IDEA .我在处理IntelliJ IDEA时遇到了这个问题。 For me it happened because I added JUnit and Mockito libraries which were being compiled at runtime.对我来说,这是因为我添加了在运行时编译的JUnitMockito库。 This needed to be set to "testing" in module properties.这需要在模块属性中设置为“测试”。

Updating Proguard to latest version solved it for me.将 Proguard 更新到最新版本为我解决了这个问题。

  • My proguard path was C:\\Program Files (x86)\\Android\\android-sdk\\tools\\proguard\\我的 proguard 路径是C:\\Program Files (x86)\\Android\\android-sdk\\tools\\proguard\\
  • I downloaded the new version from here我从这里下载了新版本
  • and replaced both bin and lib folders并替换了 bin 和 lib 文件夹

THANK GOD!感谢上帝!

In my case the problem is actually with OpenFeint API project.就我而言,问题实际上出在 OpenFeint API 项目上。 I have added OpenFeint as library project:我已将 OpenFeint 添加为库项目:

库项目]![1]![在此处输入图像描述. .

It is also added into build path, ADT tools 16 gives error with this sceneario.它也被添加到构建路径中,ADT 工具 16 给出了这个场景的错误。

Right click on your project and click build path, configure the build path and then see the image and remove your project OpenFeint from here and all is done :)右键单击您的项目并单击构建路径,配置构建路径,然后查看图像并从此处删除您的项目 OpenFeint,一切都完成了:)

在此处输入图片说明

None of previously proposed solutions worked for me.以前提出的解决方案都不适合我。 In my case, the problem happened when I switched from referencing a library source code folder to using the library JAR file.就我而言,问题发生在我从引用库源代码文件夹切换到使用库 JAR 文件时。 Initially there was an Android library project listed under the Android application project Properties\\ Android page\\ Library section, and the library compared also in project explorer tree as a link to the library source directory.最初在 Android 应用程序项目 Properties\\Android page\\Library 部分下列出了一个 Android 库项目,该库也在项目资源管理器树中作为指向库源目录的链接进行比较。

In the first place, I just deleted the directory link from the project tree and I added the JAR library to the build path, but this caused the exception.首先,我只是从项目树中删除了目录链接,并将 JAR 库添加到构建路径中,但这导致了异常。

The correct procedure was (after changing back the build path and putting back the reference to the library source):正确的过程是(在改回构建路径并放回对库源的引用之后):

  • properly remove the library source directory link by actually removing the reference from application project Properties\\ Android page通过从应用程序项目 Properties\\ Android 页面中实际删除引用来正确删除库源目录链接

  • adding the library JAR to the application project build path as usual.像往常一样将库 JAR 添加到应用程序项目构建路径。

None of the listed solutions worked for me.列出的解决方案都不适合我。

Here's where I was having a problem:这是我遇到问题的地方:

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.我首先将 jSoup 外部 JAR 文件添加到我的项目路径中,方法是将其放在名为“libs”的源文件夹中,然后右键单击它,构建路径-> 添加到构建路径。 This threw the Dalvik conversion error.这引发了 Dalvik 转换错误。 It said I had "already included" a class from that JAR file.它说我“已经包含”了那个 JAR 文件中的一个类。 I looked around the project's directory and found that the place where it was "already included" was in fact the bin directory.我查看了项目的目录,发现它“已包含”的地方实际上是bin目录。 I deleted the JAR file from the bin directory and refreshed the project in Eclipse and the error went away!我从bin目录中删除了 JAR 文件并在 Eclipse 中刷新了项目,错误消失了!

In my case就我而言

project->properties->java build path -> in order and export tab -> uncheck android-support-v4.jar项目-> 属性-> java 构建路径-> 按顺序和导出选项卡->取消选中android-support-v4.jar

Just clean the project只需清理项目

If this does not work try the other solutions如果这不起作用,请尝试其他解决方案

All the solutions above didn't work for me.上面的所有解决方案对我都不起作用。 I'm not using any precompiled .jar.我没有使用任何预编译的 .jar。 I'm using the LVL and the Dalvik errors where all related to the market licensing library.我正在使用 LVL 和 Dalvik 错误,这些错误都与市场许可库有关。

The problem got solved by deleting the main project and reimporting (create a new project from existing sources).通过删除主项目并重新导入(从现有源创建一个新项目)解决了问题。

I had the same problem and none of these solutions worked.我遇到了同样的问题,但这些解决方案都没有奏效。 Finally, I saw in the console that the error was due to duplicated class (one in the existing project, one in the added jar file) :最后,我在控制台中看到错误是由于重复的类(一个在现有项目中,一个在添加的 jar 文件中):

java.lang.IllegalArgumentException: already added: package/MyClassclass;
[2011-01-19 14:54:05 - ...]: Dx1 error; aborting
[2011-01-19 14:54:05 - ...] Conversion to Dalvik format failed with error 1

So check if you are adding jar with duplicated classes in your project.因此,请检查您是否在项目中添加了具有重复类的 jar。 If yes, try removing one of them.如果是,请尝试删除其中之一。

It worked for me.它对我有用。

Often for me, cleaning the project DOES NOT fix this problem.通常对我来说,清理项目并不能解决这个问题。

But closing the project in Eclipse and then re-opening it does seem to fix it in those cases...但是在 Eclipse 中关闭项目然后重新打开它似乎在这些情况下修复了它......

I ran into this problem but my solution was twofold.我遇到了这个问题,但我的解决方案是双重的。 1.) I had to add an Android target version under project -> properties -> Android . 1.) 我必须在project -> properties -> Android下添加一个 Android 目标版本。 2.) I didn't have all google 'third party add-ons'. 2.) 我没有所有的谷歌“第三方附加组件”。 Click in AVD SDK manager under available packages -> third-party add-ons -> Google Inc .单击可用包下的 AVD SDK 管理->第三方附加组件-> Google Inc I downloaded all of the SDKs and that solved my issue.我下载了所有的 SDK,这解决了我的问题。

I am using Android 1.6 and had one external JAR file.我使用的是 Android 1.6 并且有一个外部 JAR 文件。 What worked for me was to remove all libraries, right-click project and select Android Tools -> *Fix Project Properties (which added back Android 1.6) and then add back the external JAR file.对我有用的是删除所有库,右键单击项目并选择Android Tools -> *Fix Project Properties(它添加回 Android 1.6),然后添加回外部 JAR 文件。

I ran into this problem because the Android-Maven-plugin in Eclipse was apparently not recognizing transitive references and references referenced twice from a couple of projects (including an Android library project), and including them more than once.我遇到了这个问题,因为 Eclipse 中的 Android-Maven-plugin 显然无法识别从几个项目(包括一个 Android 库项目)中两次引用的传递引用和引用,并且不止一次地包含它们。 I had to use hocus-pocus to get everything included only once, even though Maven is supposed to take care of all this.我不得不使用 hocus-pocus 将所有内容只包含一次,即使 Maven 应该负责所有这些。

For example, I had a core library globalmentor-core, that was also used by globalmentor-google and globalmentor-android (the latter of which is an Android library).例如,我有一个核心库 globalmentor-core,它也被 globalmentor-google 和 globalmentor-android(后者是一个 Android 库)使用。 In the globalmentor-android pom.xml I had to mark the dependency as "provided" as well as excluded from other libraries in which it was transitively included:在 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>

Then in the final application pom.xml I had to use the right trickery to allow only one inclusion path---as well as not explicitly including the core library:然后在最终的应用程序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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM