How to fix the “Conversion to Dalvik format failed with error 1″ with ADT 14

Today I updated my SDK and ADT to the 14 version and I had a big problem !!

Every project I had which used Android Library Project couldn’t be launched on a terminal and crashed during the APK generation with the following error :

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/foxykeep/datadroid/config/LogConfig;
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.run(Main.java:206)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at java.lang.reflect.Method.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:179)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:729)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:602)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:629)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:172)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:282)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:363)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project$1.run(Project.java:545)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:524)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.build(Project.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.project.ProjectHelper.build(ProjectHelper.java:869)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:146)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:702)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:924)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1128)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2011-10-19 15:19:18 - MyProject] Dx
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lgreendroid/app/ActionBarActivity;
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.run(Main.java:206)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at java.lang.reflect.Method.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:179)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:729)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:602)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:629)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:172)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:282)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:363)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project$1.run(Project.java:545)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:524)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.build(Project.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.project.ProjectHelper.build(ProjectHelper.java:869)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:146)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:702)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:924)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1128)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2011-10-19 15:19:23 - MyProject] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
[2011-10-19 15:19:23 - MyProject] Dx 2 errors; aborting
[2011-10-19 15:19:23 - MyProject] Conversion to Dalvik format failed with error 1

After searching the web and finding this existing bug in the Android bugtracker, I found the reason of this crash . Below you can see my project hierarchy before and after the update from ADT 12 to ADT 14 :

There is only 3 visible differences : “Library Projects” and a “bin” folder and the “default.properties” has been rename to “project.properties”.

The problem here is that the Library Projects elements contains for each Android Library Projects a jar file with the source code. At the same time we still have the GreenDroid_src and DataDroid_src elements which also contains the source code of the libraries. So we have duplicated code in our projects as mentioned in the error.

I think the update should have removed the useless X_src elements but it’s not the case. So we will have to do it manually :

  1. For each X_src element,right click on it and then Build Path > Remove from build path.
  2. A popup will open. Make sure that “Also unlink the folder from the project” is checked and then accept it.
Your project should changed from the left image to the right one :

Now you can launch your project and it should work !

Similar Posts:

Leave a comment ?

35 Comments.

  1. Santiago Ennis (1 comments)

    Thank you very much! :grin:

  2. jimmy (1 comments)

    thanks, this works on my own apps too…

  3. +1

  4. ayanir (1 comments)

    when I uses a debugger then is says that the code couldn’t be found.
    have you manage to debug the source in the libraries?

  5. Foxykeep (47 comments)

    I’ve just test it with one of my projects and it’s working without problem…
    And I think it’s not linked to the problem I describe here.
    You should open a new bug on http://code.google.com/p/android/

  6. Thanks, I was pulling my hair out trying to figure out what was happening, Your clean explanation made it easy :)

  7. Qi (1 comments)

    ” I was pulling my hair out trying “, too. Oh they put wrong variables in default ant build.xml, they forgot to pack classes for monkeyrunner, they broke “wipe data”…..

  8. Foxykeep (47 comments)

    Yep not the best upgrade script … :)

  9. Thank you! Shame on Google, not paying attention that an update would break everyone’s project. Thanks Foxykeep for the help here! :)

  10. Marcus Wolschon (1 comments)

    The same problem happens with Maven+Eclipse builds without any library project.
    (android.jar msut be a maven dependency and is thus in the classpath. But Android for Eclipse adds it again, so it’s in there twice and with forbidden package-names like java.* and javax* nonetheless.)

    No solution there.

  11. Hi there, thanks for the post. It saved me a lot of time.

    Speaking of greendroid library, I am still having an issue. When I try to override gdActionBarApplicationDrawable and the other stuff related to the action bar, the xml parser says that it could not find gdActionBarApplicationDrawable attribute, as if it could not find it from the greendroid jar. Am I missing something? As anybody experienced anything similar?

  12. Someone (1 comments)

    Thank you!

  13. I found the solution of my issue. It may help somebody (maybe) so I write it down here.

    The exact error was “No resource found that matches the given name” referring attributes defined in the library project (greendroid in this case).

    I was importing the jar generated from the bin folder of the library project into the Java build path property instead of adding it as a library into the android property of my project.

    Thanks for the excellent post.

  14. asato (1 comments)

    Thank you!

  15. Bob (1 comments)

    Thank you! Good eye!

  16. Sasa (1 comments)

    Thanks!

  17. I still get “Conversion to Dalvik format failed with error 1″ – does not work for me

  18. If you use GreenDroid: using the GoogleAPI version of GreenDroid won’t work because it refers to the normal GreenDroid project and it causes “Conversion to Dalvik format failed with error 1? with ADT 14.. of course it’s a bug..

  19. Breno (1 comments)

    Hey this since my case is a little bit different I’m still having the “already added” problem. Here’s the scenario: I have a MAIN_PROJECT that uses libraries A B and C. And also, A uses B. So I add B to A, and A and C to the MAIN_PROJECT…
    This still causes the already added problem.
    Anyone?

  20. Devizor (1 comments)

    Thank you!!!!

  21. avollmer (1 comments)

    Breno:

    I had this same problem occur, even after deleting all of the references. If you’re using eclipse, you need to modify the references in the project itself; Right click your project, go to properties, then go to “Project References”. Start unchecking.

    I don’t know why but ADT does use this for dex.

  22. Michael Little (1 comments)

    After days of searching and trying different suggested fixes, this was the only thing that worked for me. Thanks so much for posting this.

  23. Same issue, thank you so much!

  24. vinay (1 comments)

    I have a Library project which uses APIs from jar. When I reference this Library project from an application which also uses the APIs from the same jar, I’m getting above error message. How would I solve it??

  25. Foxykeep (47 comments)

    The problem I think is that your library is double referenced. Once in your lib project and another time in your main project. So remove it from your main project and you’ll have access to it from your lib project.

  26. Soraia Oliveira (1 comments)

    thank you! it helped me too much… best regards!

  27. great!!! Helped me a lot.thanks

  28. sara (1 comments)

    thanx a lot, it helped me too much

Leave a Reply

Page optimized by WP Minify WordPress Plugin