ashughes
ashughes

Reputation: 7233

"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.

Upvotes: 6

Views: 10755

Answers (10)

mvmanh
mvmanh

Reputation: 161

I've dealt with this problem when using Sherlock ActionBar library in my project. You could do the following step, it's work for me.

Right click to your project, select properties. A dialog will show up, select 'Java build path' on the left menu. Remove 'Android dependencies' and 'Android private libraries' on the right panel then click OK Clean your project (select menu Project --> Clean) Right click your project, select Android Tools -> Fix project properties Clean project once again. Restart your computer Open eclipse and Export apk Hope that will help you.

Upvotes: 0

Sam
Sam

Reputation: 6395

I had the same issue, I'm using the ADT 20.0.3.

Steps I followed to resolve this.

Remove all the jar in project/lib folder and reference them as external jars. Check android dependencies/reference libraries in project for duplicates,

Upvotes: 0

Chu Chau
Chu Chau

Reputation: 70

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.

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.

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.

Upvotes: 0

Simon
Simon

Reputation: 1

Just had this problem come back again (fixed first time by removing the _src items as mentioned in other answers) - this time there were no _src files to remove. The error was relating the android-support-v4.jar which was included as part of a linked library project as well as part of the main project itself.

Error Dx UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Landroid/support/v4/content/ModernAsyncTask$WorkerRunnable;

Problem went away after removing the android-support-v4.jar file from the build path for the main project. Don't think I came across this as possible cause to the errors.

Upvotes: 0

Kit Ramos
Kit Ramos

Reputation: 1878

Hello thought I'd throw my two cents in here. as I did do that,

"_src -> Remove from path"

Then I cleaned it and rebuilt and I could get it to run in debug mode on my phone just fine. I could also export it; but only if I disabled proguard. of course I couldn't leave it like that with my code open for all to see. so it was quite madding. but I Finally found a cure, oddly enough they had the same problem (and fix) with r12 as they do with this one.

it's in: [Android SDK Installation Directory]\tools\proguard\bin\proguard.bat

Change

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

I tried tons of other stuff but this is what did it for me.

Upvotes: 1

Joe Fernandez
Joe Fernandez

Reputation: 4811

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!

Upvotes: 6

ashughes
ashughes

Reputation: 7233

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).

Upvotes: 8

Mangusto
Mangusto

Reputation: 1505

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"

Upvotes: 5

J.G.Sebring
J.G.Sebring

Reputation: 5964

I used a library for my project and had the same error - it was solved by removing library and src-folder, cleaning and adding it back and cleaned again.

Remove

  1. Project properties -> Android: Remove libs, 'Apply'
  2. Remove included library src-folder
  3. better clean,

Add again

  1. Project properties -> Android: Add libs again, 'Apply'
  2. Clean project

Upvotes: 0

Kurtis Nusbaum
Kurtis Nusbaum

Reputation: 30825

This is a known problem with the android sdk. Check out this blogpost for a fix.

Upvotes: 0

Related Questions