Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Conversion to Dalvik format failed with error 1" after update to ADT 14

After updating to the latest developer tools, ADT 14, my Android project that includes library projects will no longer run producing the error:

Dx UNEXPECTED TOP-LEVEL EXCEPTION: ... already added: ...
...
Conversion to Dalvik format failed with error 1

The other threads describing this issue with solutions that include removing and re-adding the projects do not work.

like image 834
ashughes Avatar asked Oct 22 '11 17:10

ashughes


3 Answers

This problem is listed as a known issue of ADT 14. Here's the quote from the Android Tools Project Site:

Project not building with error [2011-10-20 23:32:04 - MyApp] Dx UNEXPECTED TOP-LEVEL EXCEPTION:<class>: already added: <class> This is due to a failure to remove previous library source folders from the main project. Incidentally, the fragility around those linked source folders is one of the reason we are moving away from this mechanism (see more info at http://tools.android.com/recent/buildchangesinrevision14). The solution is to remove those <libraryname>_src source folders from your projects. Just right click them and choose Build Path > Remove from Build Path. You should also be prompted to remove the linked folder which you should do. If you're not prompted, remove it manually. You can see some screenshot of the problem in this great post: http://android.foxykeep.com/dev/fix-the-conversion-to-dalvik-format-failed-with-error-1-with-adt-14

Solution:

As it says, the solution is to remove the <libraryname>_src source folders from your projects. You can do this by right clicking them and choose "Build Path -> Remove from Build Path" or in your project properties (Java Build Path -> Source tab).

like image 187
ashughes Avatar answered Oct 30 '22 19:10

ashughes


I also ran into this problem, but none of the above fixed it:

  • Tried removing/re-adding libraries with clean builds along the way
  • Tried deleting and re-importing projects

No dice. Still the "Conversion to Dalvik format failed with error 1" was staring me in the face every time I tried to export to an apk.

I could tell the problem was related to ProGuard, because when I commented out this line in my project.properties file, everything worked fine:

proguard.config=proguard.cfg

However, I wasn't able to solve the problem until I found this post by David M Young. Apparently, ADK/ADT 14 shipped with an incorrect version of ProGuard (oops!). I downloaded ProGuard version 4.6. Replaced the android-sdk\android-sdk\tools\proguard\lib directory contents with proguard4.6.zip\proguard4.6\lib (3 *.jar files), restarted Eclipse and export to apk worked again!

like image 6
Joe Fernandez Avatar answered Oct 30 '22 19:10

Joe Fernandez


To solve you should:

  • Right click on your project>Properties>Java Build Path and remove all libs but the one Android I.J (depending on your version)
  • Project>Clean
  • Add back the libs you've removed

If the problem comes back another times it's useful to put the libs outside your project and import them as "External JARs"

like image 5
Mangusto Avatar answered Oct 30 '22 19:10

Mangusto