Android:获取错误:转换为 Dalvik 格式失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2759793/
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
Android: Getting Error: Conversion to Dalvik format failed
提问by Rupesh C
I am building an app on android and running into an error and while searching on net, came across your posting on this and changed the eclipse.ini to increase Xms and Xmx params but still this error does not go away.
我正在 android 上构建一个应用程序并遇到错误,在网上搜索时,遇到了您在此发布的帖子,并更改了 eclipse.ini 以增加 Xms 和 Xmx 参数,但此错误仍然没有消失。
I am using Eclipse IDE for Java with Android SDK 2.1 on Mac OS. Please help or please point me to someone who might know.
我在 Mac OS 上使用 Eclipse IDE for Java 和 Android SDK 2.1。请帮助或请指出我可能知道的人。
Btw, this error only happens when i add external jar files (which i need for my project). Here are the list of external jar files that i have in my classpath.)
顺便说一句,此错误仅在我添加外部 jar 文件(我的项目需要)时发生。这是我的类路径中的外部 jar 文件列表。)
- httpclient-4.0.1.jar from apache
- httpcore -4.0.1.jarfrom apache
- commons-codec-1.3.jar from apache
- commons-logging-1.1.1.jar from apache
- json_simple-1.1.jar from google
- 来自 apache 的 httpclient-4.0.1.jar
- httpcore -4.0.1.jar 来自 apache
- 来自 apache 的 commons-codec-1.3.jar
- 来自 apache 的 commons-logging-1.1.1.jar
- 来自谷歌的 json_simple-1.1.jar
Here is the complete error:
这是完整的错误:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/AvalonLogger;
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.dex.file.DexFile.add(DexFile.java:143)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.command.dexer.Main.processClass(Main.java:301)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.command.dexer.Main.processFileBytes(Main.java:278)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.command.dexer.Main.access0(Main.java:56)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.command.dexer.Main.processFileBytes(Main.java:229)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.cf <http://com.android.dx.cf.direct.ClassPathOpener.pro> .direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.command.dexer.Main.processOne(Main.java:247)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.dx.command.dexer.Main.run(Main.java:139)
[2010-05-02 21:57:05 - MyApp] ??? at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2010-05-02 21:57:05 - MyApp] ??? at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[2010-05-02 21:57:05 - MyApp] ??? at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[2010-05-02 21:57:05 - MyApp] ??? at java.lang.reflect.Method.invoke(Method.java:592)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.ide.eclipse.adt.internal.sdk.DexWrapper.run(Unknown Source)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.ide.eclipse.adt.internal.build.ApkBuilder.executeDx(Unknown Source)
[2010-05-02 21:57:05 - MyApp] ??? at com.android.ide.eclipse.adt.internal.build.ApkBuilder.build(Unknown Source)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.BuildManager.run(BuildManager.java:627)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.BuildManager.run(BuildManager.java:253)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
[2010-05-02 21:57:05 - MyApp] ??? at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
[2010-05-02 21:57:05 - MyApp] 4 errors; aborting
[2010-05-02 21:57:05 - MyApp] Conversion to Dalvik format failed with error 1
回答by ndyer
In r14 they changed the way in which external libraries are referenced and it can cause this problem. You can fix it by removing the linked folders (with _src in the name) from the folder tree:
在 r14 中,他们更改了引用外部库的方式,这可能会导致此问题。您可以通过从文件夹树中删除链接的文件夹(名称中带有 _src)来修复它:
- Right click and select "Build Path > Remove from build path"
- A popup will open. Make sure that “Also unlink the folder from the project” is checked and then accept it.
- 右键单击并选择“构建路径 > 从构建路径中删除”
- 将打开一个弹出窗口。确保选中“同时取消项目与文件夹的链接”,然后接受它。
see http://android-developers.blogspot.co.uk/2011/10/changes-to-library-projects-in-android.html
见http://android-developers.blogspot.co.uk/2011/10/changes-to-library-projects-in-android.html
回答by CommonsWare
UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/AvalonLogger;
意外的顶级异常:java.lang.IllegalArgumentException:已添加:Lorg/apache/commons/logging/impl/AvalonLogger;
You are attempting to add org.apache.commons.logging.impl.AvalonLogger
twice to your project. Do not do that.
您正在尝试向org.apache.commons.logging.impl.AvalonLogger
项目中添加两次。不要那样做。
Also, much of what you are adding via JARs is already in Android, such as HttpClient. This may be contributing to your error.
此外,您通过 JAR 添加的大部分内容已经在 Android 中,例如 HttpClient。这可能会导致您的错误。
回答by Gray
I just had this as well but I made sure ahead of time that I did not have a duplicate class in my jar file. This was some other issue dealing with multiple loading of the same jar or something. The classpath and the list of Referenced Libraries looked appropriate. After some flailing around, some combination of the following fixed it:
我也有这个,但我提前确保我的 jar 文件中没有重复的类。这是处理同一个 jar 或其他东西的多次加载的其他问题。类路径和引用库列表看起来很合适。经过一番折腾,以下的一些组合修复了它:
- I was using a different external jar that was also local in the directory. I removed it from the build-path and re-added it from the local jar instead.
- I removed all external jars and re-added them one at a time making sure they were the right ones.
- I removed the .classpath file in my project as well as the bin and gen directories.
- I cleaned the project in Eclipse, forcing the files to be regenerated.
- I also shuffled around the jar file above the gen directory in the build order.
- 我使用了一个不同的外部 jar,它也在目录中是本地的。我从构建路径中删除了它,而是从本地 jar 中重新添加了它。
- 我移除了所有外部罐子,并一次重新添加一个,以确保它们是正确的。
- 我删除了项目中的 .classpath 文件以及 bin 和 gen 目录。
- 我在 Eclipse 中清理了项目,强制重新生成文件。
- 我还在构建顺序中围绕 gen 目录上方的 jar 文件进行了调整。
Some combination of the above seemed to fix the issue. If it happens again, I will be more careful to see if I can reproduce it.
以上的一些组合似乎解决了这个问题。如果再次发生,我会更加小心,看看我是否可以重现它。
回答by omermuhammed
回答by phongvan_fls
i guess that you put your jar in folder for example library and then, build path from this folder. You just remove this jar file and try select propertyfrom project, then Java build path-> Add external jarsfiles. It will works fine.
我猜你把你的 jar 放在文件夹中,例如 library,然后从这个文件夹中构建路径。您只需删除此 jar 文件并尝试从项目中选择属性,然后选择Java 构建路径->添加外部 jar文件。它会正常工作。
回答by Jeffrey Yasskin
I had this problem because I put the .jar under my src/
directory, so Eclipse copied it to the bin/
directory and tried to link it from both places. Moving it from src/
to libs/
fixed the problem.
我有这个问题,因为我把 .jar 放在我的src/
目录下,所以 Eclipse 将它复制到bin/
目录并尝试从两个地方链接它。将其从src/
移至libs/
解决了问题。
回答by Peterdk
My problem was due to having the same project references also in library projects. A few updates ago this was normal behaviour, but since the change in library handling, I now needed to remove the references from my projects and have only one of the libraries reference it.
我的问题是由于在库项目中也有相同的项目引用。几次更新前,这是正常行为,但由于库处理的变化,我现在需要从我的项目中删除引用,并且只有一个库引用它。
回答by Pete
This always happened to me after I did a custom build using a custom command using proguard.
在我使用 proguard 使用自定义命令进行自定义构建后,这总是发生在我身上。
I solved this problem by emptying the bin directory of my eclipse project directory and then cleaning the project (Eclipse menu "project" --> "clean...")
我通过清空我的 eclipse 项目目录的 bin 目录然后清理项目(Eclipse 菜单“项目”-->“清理...”)解决了这个问题
Obviously proguard makes a mess in this directory by which Eclipse gets confused...
显然 proguard 在这个目录中弄得一团糟,使 Eclipse 感到困惑......
回答by Pelanes
I get really mad with this problem trying to do all the posible solutions, but none worked for me: Clean project, Re-build, erasing libraries, linking again the libraries, updating proguard, editing proguard files...
我对这个问题非常生气,试图做所有可能的解决方案,但没有一个对我有用:清理项目,重新构建,擦除库,再次链接库,更新 proguard,编辑 proguard 文件......
Finally the solution was much more easy: Project, Android Tools, Fix project propieties.
最后,解决方案要简单得多:Project、Android Tools、Fix project propieties。
Now I can export the apk.
现在我可以导出 apk。
回答by Cirem
Right click the src and gen folders and select Build Path > Remove from Build Path. then Right Click > Build Path > Use as Source Folder
右键单击 src 和 gen 文件夹并选择 Build Path > Remove from Build Path。然后右键单击>构建路径>用作源文件夹