Android 外部 JAR 上的“转换为 Dalvik 格式失败,错误 1”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2680827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Conversion to Dalvik format failed with error 1" on external JAR
提问by Michel
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;
....
Conversion to Dalvik format failed with error 1
意外的顶级异常:
java.lang.IllegalArgumentException:已添加:Lorg/xmlpull/v1/XmlPullParser;
....
转换为 Dalvik 格式失败,错误 1
This error only appears when I add a specific external JAR file to my project. I searched for a long time for the possible solution, but none of the possible solutions work.
仅当我将特定的外部 JAR 文件添加到我的项目时才会出现此错误。我搜索了很长时间以寻找可能的解决方案,但没有一个可能的解决方案有效。
I even tried to change to Android 1.6 instead of 1.5 (the current version I use).
我什至尝试更改为 Android 1.6 而不是 1.5(我使用的当前版本)。
采纳答案by Michel
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.jar
和 android_maps_lib-1.0.2
Deleting this package from one of the JAR files solved the problem.
从其中一个 JAR 文件中删除这个包解决了这个问题。
回答by user408841
Go to Project ? Properties ? Java Build Path ? Libraries and remove all except the "Android X.Y" (in my case Android 1.5). click OK. Go to Project ? Clean ? Clean projects selected below ? select your project and click OK. That should work.
去项目?特性 ?Java构建路径?库并删除除“Android XY”之外的所有库(在我的情况下为 Android 1.5)。单击确定。去项目?干净的 ?下面选择的清洁项目?选择您的项目,然后单击“确定”。那应该工作。
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. 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.
也有可能您的项目文件夹中的某个位置有一个 JAR 文件(我已将 Admob JAR 文件复制到我的 src 文件夹中),然后将其添加为 Java 路径库。它没有出现在包资源管理器下,所以你不会注意到它,但它确实被计数了两次,导致可怕的 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. This means, you have multiple references to the same file A.java
and can't properly build it.
另一个可能的原因可能是包名冲突。假设您有一个包com.abc.xyz
和一个A.java
在该包中命名的类,以及另一个包含相同 的库项目(已添加到该项目的依赖项中)com.abc.xyz.A.java
,那么您将得到完全相同的错误。这意味着,您对同一个文件有多个引用,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 后删除该路径代码将正常工作。如果仍然出现任何问题,请检查此内容。
回答by Noah
Windows 7 Solution:
Windows 7 解决方案:
Confirmed the problem is caused by ProGuard command line in the file
[Android SDK Installation Directory]\tools\proguard\bin\proguard.bat
确认问题是文件
[Android SDK安装目录]\tools\proguard\bin\proguard.bat中的ProGuard命令行导致的
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
回答by Ton Snoei
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. After that, don't forget to turn it on again.
您可以通过在导出(未)签名的 Android 应用程序时关闭菜单 >“项目”>“自动构建”来轻松解决此问题(使用 Eclipse Android 开发者工具,构建:v22.0.1-685705)。之后,不要忘记再次打开它。
回答by Kocus
If you have ADT revision 12+, you should update your proguard from 4.4 -> 4.6 (as described here). Also, you should leave ...\bin\proguard.bat file in the orginal form.
如果你有ADT修订12+,你应该从4.4更新您的ProGuard - > 4.6(描述在这里)。此外,您应该保留原始格式的 ...\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
回答by Paveliko
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
Export your app as a signed APK while Build Automatically is still disabled
转到项目-> 取消选中自动构建
转到 Project -> Clean... ,同时清理库项目和您的应用项目
将您的应用导出为已签名的 APK,而“自动构建”仍处于禁用状态
回答by miko?ak
Here's another scenario, and solution:
这是另一个场景和解决方案:
If you run into this problem recently after updating the ADT for Eclipse:
如果您最近在为 Eclipse 更新 ADT 后遇到此问题:
- In your app project, check for any linked source folders pointing to your library projects (they have names in the form "LibraryName_src").
- Select all those projects, right-click, choose "Build Path"->"Remove from Build Path".
- Choose "Also unlink the folder from the project", and click "Yes".
- Clean, rebuild and redeploy the project.
- 在您的应用项目中,检查是否有任何指向您的库项目的链接源文件夹(它们的名称为“LibraryName_src”形式)。
- 选择所有这些项目,右键单击,选择“构建路径”->“从构建路径中删除”。
- 选择“同时取消文件夹与项目的链接”,然后单击“是”。
- 清理、重建和重新部署项目。
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 段以后。
回答by kgandroid
Go to Project and then uncheck "Build Automatically".Then try to export the project and the error is gone.
转到项目,然后取消选中“自动构建”。然后尝试导出项目,错误消失了。
回答by Thomas Dignan
This can also be caused if you have added Android.jar
file to your build path, perhaps by an accidental quick fix in Eclipse. Remove it with right clicking Project-> build path-> configure build path-> android.jar, remove.
如果您已将Android.jar
文件添加到构建路径,也可能是由于 Eclipse 中的意外快速修复而导致的。右键单击Project-> build path-> configure build path-> android.jar删除它,删除。
回答by BTR
Simply cleaning the project has worked for me every time this error has come up.
每次出现此错误时,简单地清理项目对我都有效。