924

In my Android application in Eclipse, I get the following error.

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lorg/xmlpull/v1/XmlPullParser;
....
Conversion to Dalvik format failed with error 1

This error only appears when I add a specific external JAR file to my project. I searched for a long time for a possible solution, but none of them work.

I even tried to change to Android 1.6 instead of 1.5 (the current version I use).

The Amateur Coder
  • 789
  • 3
  • 11
  • 33
Michel
  • 9,220
  • 13
  • 44
  • 59
  • 4
    I tried this and it gave same error. I finally fixed it by adding the library in Properties->JavaBuildPath->Projects and add the library there. Its called "Required objects on the build path:". –  Apr 06 '12 at 19:28
  • [This acticle](http://android.foxykeep.com/dev/fix-the-conversion-to-dalvik-format-failed-with-error-1-with-adt-14) may help you to fix this error in case that you use library project in your workspace. – Nguyen Minh Binh Mar 06 '12 at 03:01
  • 27
    This problem has become brutal for me. It's almost enough to give up Android coding. None of the solutions work for me. I simply have to continuously try to export failing with Dalvik error 1 and eventually it will succeed. It takes 15-30 minutes to make a release build. It's a complete disaster. – Anthony Mar 01 '13 at 08:06
  • If you use two computers on one workspace with a file share software, it sometimes duplicates workspace->project->bin->com folder as com 1, com 2. Simply delete everything with 1 or 2, clean your project and you are ready to go. – Ozan Atmar Jul 21 '14 at 15:40

71 Answers71

824

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.

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.

Lijo John
  • 578
  • 8
  • 21
user408841
  • 2,147
  • 2
  • 12
  • 3
  • 4
    I had the same issue and the above steps by user408841 worked for me. – Arunabh Das Aug 14 '10 at 11:29
  • thanks, this worked when getting the same error with spring for android. – scottyab Dec 19 '10 at 14:04
  • 112
    Hi. It fixes for me just by going "Project » Clean » Clean projects selected below » select your project and click OK." ignoring the 1st bit – Kurru Jan 06 '11 at 20:55
  • 1
    Worked for me. I had to restart Eclipse Helios 2ce afterwards. Whenever a project is cleaned it seems that 2 Eclipse restarts are necessary to get it back in shape. Just let Eclipse load the workspace before restarting. – Alex Apr 13 '11 at 04:14
  • 1
    If you have a library in another project in the workspace this can occur. Say if you have two projects, each with a.jar in them, but one of them is *exporting* a.jar.. You need to either stop exporting it or remove the lib from the other projects. – Thomas Dignan Jun 19 '11 at 23:43
  • Maybe this is a little obvious but it your project references a library that is in the same workspace, retain that library. Don't necessarily delete all the libraries in the library tab. I ran into this problem when I updated my MOTODEV with a fresh install – gjpc Nov 20 '11 at 16:13
  • @user408841: I impress with your profile just one answer and 1930 reputation, amazing no question.Are you active on StackOverflow? – Tofeeq Ahmad Jan 07 '12 at 06:36
  • why isn't this the accepted answer dhaval? because this will totally muck things up if you're referencing other libraries. for example, the standard implementation of LVL licensing. not to mention the fact that he doesn't even explain why. the fact that 197 people voted this answer up only goes to show that a _minimum_ of 197 people were stupid enough to go around deleting crap to which they had no idea what they were deleting. – arkon Jan 10 '12 at 11:22
  • THANKS SO MUCH!! you had the most perfect answer.. It solved my problem like a magic! :) – CMA Jan 11 '12 at 11:24
  • 1
    This doesn't work for me because I ~USE~ the libraries in my Java Build Path, like Google Analytics and a 3rd party audio library. – Nick Gotch Jan 24 '12 at 06:50
  • 80
    I am quite confusing with this solution. If you remove all jar files and libraries, how are you going to compile the project successfully? – Cheok Yan Cheng Feb 02 '12 at 02:57
  • This worked for me—I think it's because they've added an "Android Dependencies" folder that included duplicates of things I'd added myself. – Ben Gotow Mar 30 '12 at 04:51
  • 1
    It didn't work for me, but I solved the problem by cleaning up `gen` folder of a library. Which one of your libraries (and specific `gen`) causes the problem can be deduced from the message of `already added` entity. Please note that this is not the package which is mentioned in the message (as it was in my case with a duplicated id), but another package which uses the mentioned one. Do a context search through entire project. – Stan Jun 12 '12 at 21:03
  • 3
    I found that the only way this worked for me was to CLEAN ALL PROJECTS! Especially ones that the offending project depends on. – Roy Hinkley Jul 12 '12 at 20:58
  • 7
    I'm new to Android development coming from .NET, and to be honest this error epitomises my experience with it. Seriously... what are you meant to do with that error message? It's totally meaningless. 'Dalvik'?? You what?? Get me back to visual studio :p – David Masters Sep 11 '12 at 16:06
  • I was exporting same library twice, in two different projects, removing on one fixed it for me – tsukimi Nov 15 '12 at 05:49
  • Thank you !! It works for me when I removed all the projects from: properties- Android - the window in the bottom , and then re-add them and clean – Chris Sim Mar 08 '13 at 11:25
  • Keep the Android X.X.X AND the Android Dependencies folders -- otherwise you'll mess up your build. Remove the other jars, clean, and then add them back. – Catherine Darrow Jul 15 '13 at 19:51
  • I removed exporting Android dependencies from the android-support-v7-appcompat project that I had created, and did a clean and this worked. – Meanman Dec 27 '13 at 12:19
  • In general, it seems that this problem comes when there are unnecessary JAR files in build path. – mindreader Mar 30 '14 at 03:50
  • I had two activties with same name but in different pakages. I just change the names and it worked for me – Qadir Hussain Jul 25 '14 at 07:39
  • I had the same issue and the above steps by user408841 worked for me. – vasan Oct 21 '14 at 11:25
  • If Error Occured, Solve with `Right Click on Project -> Android Tools -> Fix Project Properties` – Pratik Butani Dec 02 '14 at 05:46
  • Worked for me by simply cleaning the project. Skipping step #1 – Aymeric Gaurat-Apelli Jan 20 '15 at 22:50
  • A bad .jar file can also cause the same issue – Danke Xie Jan 12 '16 at 22:29
274

I solved the problem.

This is a JAR file conflict.

It seems that I have two JAR files on my buildpath that include the same package and classes.

smack.jar and android_maps_lib-1.0.2

Deleting this package from one of the JAR files solved the problem.

Yksh
  • 3,276
  • 10
  • 56
  • 101
Michel
  • 9,220
  • 13
  • 44
  • 59
  • 18
    +1 - In summary, this is a JAR file conflict. Specifically, this could be a conflict in *any* two JAR files. In my case, the conflict was between jackson-all-1.7.4.jar, jackson-core-asl-1.5.4.jar, and jackson-mapper-asl-1.5.4.jar. I removed the two 1.5.4 JAR's and left the 1.7.4 all. – jamesmortensen Jun 12 '11 at 22:53
  • If you have jars in any library projects you've added on your own project, like how I had added the `ScoreloopUI` project to my AndEngine game, these jars also interfere with yours, even though they are not on your own project's build path. – pqn Jul 20 '11 at 04:08
  • 1
    I had specified android-sdk/platforms/android-10/android.jar manually in .classpath, then I changed to 2.3.3 (Android 10) in the project properties which caused both android.jar's to conflict. Removing the extra in the Java Build Path did the trick – Tyler Aug 04 '11 at 18:50
  • 2
    On my side the conflict came from the ActionbarSherlock which already includes the android support package which git included twice. – Tobias Apr 05 '12 at 20:03
  • Just for information: In my case, because of the fail, it was that the different android target was not the same in both project: android:targetSdkVersion="xx" – Andreas Mattisson Sep 21 '14 at 10:33
  • I added two jar files, android.jar and android-support-V.jar , and I removed both and got success. Saved me. – Sanjay Bhimani Nov 11 '14 at 07:47
  • had the same problem with the dropbox sdk ... i had one extra .jar (android.jar) from the dropbox packet which was not needed. i deleted it and the problem was solved – MTurPash May 07 '15 at 08:21
127

Windows 7 Solution:

Confirmed the problem is caused by ProGuard command line in the file
[Android SDK Installation Directory]\tools\proguard\bin\proguard.bat

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
Noah
  • 15,080
  • 13
  • 104
  • 148
  • this didn't work for me, but commenting out the proguard line from my default.properties file did make the error go away. my problem does seem to be related to proguard somehow. i was only getting "Conversion to Dalvik format failed with error 1" when trying to export the project. any thoughts? – Ben H Aug 22 '11 at 23:42
  • i tried the above suggestion again, and removed and re-added my LVL library project, and now it works. not sure what exactly fixed it, but it works. thank god. i wasted hours on this. – Ben H Aug 22 '11 at 23:54
  • Windows Vista, and this worked for me. I had previously tried changing the path of the SDK to progra~2, reinstalling, cleaning the project, removing the libraries and fixing, etc... So thanks Noah! – Mudar Sep 06 '11 at 19:14
  • Thank you so much Noah, this worked for me also on Windows 7. The error started after I updated ADT to version 12. – Kevin Sep 08 '11 at 16:52
  • Solved my issue on Windiws 7. – poiuytrez Oct 21 '11 at 12:04
  • Perfect for Windows 7 / android developer – hanumant Nov 18 '11 at 09:25
  • Thanks a million, Windows 7 x86 – While-E Dec 12 '11 at 07:03
  • Correct solution, works well. Commenting the proguard line would probably do the same thing, however would just stop obfuscating ur code as well. So this one is the right solution. But yes I am on windows 7, that may be the difference. – Sharique Abdullah Dec 13 '11 at 14:00
  • This answer is underrated, nice one – magritte Mar 17 '12 at 20:10
  • Been having this problem off and on in Win 7. This solution appears to work...(for now) – arkon May 09 '12 at 04:16
  • hello, i tried it but also i can not solve my problem, my OS in windows 8 - 64 bit. – Hiren Patel Apr 13 '13 at 11:52
  • Using only this (and none of the other solutions to this question) solved it on Win8.1 as well. – tomsv Jun 12 '14 at 18:28
94

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.

Ton Snoei
  • 2,637
  • 22
  • 23
  • 2
    This solved it in my case. The problem otherwise occurs sporadically and without definitive cause (e.g. bad jar or path) – D2TheC Oct 04 '13 at 09:18
  • This was driving me nuts! A the only solution that worked for me. Wonder why. – PrivusGuru Jan 31 '14 at 21:38
  • 1
    This solved for me - other solutions might have helped also, but this one was the final one before getting it to work. – pertz Feb 04 '14 at 20:59
  • I've spent 4 hours working through every suggestion I could find and finally got to this one. Thanks - it solved the problem immediately. – Squonk Feb 07 '14 at 03:44
  • Very simple solution, but it works! Saved me a few hours of pointless fight with Eclipse. Try it before you try any more complicated solution. – fragon Mar 04 '15 at 09:13
53

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.

Just download it from the web, and copy lib folder from downloaded package to the :

[Android SDK Installation Directory]\tools\proguard\lib

Kocus
  • 1,613
  • 17
  • 31
  • 3
    This has been my issue across multiple ADTs. Downloading and replacing the proguard JARs works. – Mr. S Nov 06 '11 at 20:00
  • Wow, thanks, this fixed it for me, although I also needed to clear up some warnings as well. http://stackoverflow.com/q/4525661/38258 – Nick Gotch Jan 24 '12 at 08:31
  • i changed proguard version from 4.4 to 4.9, after that my problem still not solved. – Hiren Patel Apr 13 '13 at 13:36
  • 1
    I just had to do this myself, going from 4.7 -> 4.11 (latest as of now here: http://sourceforge.net/projects/proguard/files/). I just renamed the old `/tools/proguard` dir and moved the complete unzipped `proguard4.11` dir to the old path. Voila! Now if only I could get my previous hour back... -_- – qix Jun 30 '14 at 22:00
  • 1
    Thanks! this solve my issue right. My problem is caused when i update my sdk from sdk manager and the proguard has been reset to the original version that came with it with api level 11. After i update the proguard,jar to latest version. and it works! My reference: http://java.dzone.com/articles/my-reminder-how-fix-conversion – mmw5610 Mar 25 '15 at 20:29
41

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.

I found this error by performing Lint Check (Android Tools / Run Lint: Check for Common Errors)

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

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

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Paveliko
  • 53
  • 2
  • 8
30

Here's another scenario, and solution:

If you run into this problem recently after updating the ADT for Eclipse:

  1. In your app project, check for any linked source folders pointing to your library projects (they have names in the form "LibraryName_src").
  2. Select all those projects, right-click, choose "Build Path"->"Remove from Build Path".
  3. Choose "Also unlink the folder from the project", and click "Yes".
  4. Clean, rebuild and redeploy the project.

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.

EDIT: this is confirmed by an Android Dev Blog entry, specifically this one - see the 8th paragraph onwards.

mikołak
  • 9,605
  • 1
  • 48
  • 70
  • 1
    This is by far the most helpful answer to [my particular problem](http://stackoverflow.com/questions/8828255/conversion-to-dalvik-format-failed-with-error-1-why). Thank you so much!!! – Bill The Ape Jan 12 '12 at 05:53
  • This is what I could use successfully, not the highly upvoted answer by user408841. – rics Mar 01 '12 at 12:30
29

Go to Project and then uncheck "Build Automatically".Then try to export the project and the error is gone.

kgandroid
  • 5,507
  • 5
  • 39
  • 69
27

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Thomas Dignan
  • 7,052
  • 3
  • 40
  • 48
25

Simply cleaning the project has worked for me every time this error has come up.

BTR
  • 4,880
  • 4
  • 24
  • 21
  • Restarting Eclipse + cleaning the project + manual build worked for me. – dodgy_coder Jul 06 '13 at 12:18
  • Cleaning worked for me....so if you have a good debug build that you have been running on actual phones and then go to release export and see this error... try the clean all projects first. – lepert Sep 12 '13 at 16:01
16

My own and only solution that I found today after four hours of testing all the solutions, is a combination of many solutions provided here:

  • Delete project from Eclipse
  • Delete files in \bin and \gen from project folder
  • Remove references to libraries into .classpath file in root project folder
  • Restart Eclipse with command line : eclipse -clean
  • Import project
  • Right click on project - select Properties > Java Build Path > Libraries and remove everything else than Android XX.Y
  • Finally clean project, wait for automatic Building or Build it
  • Launch and now it works! At least for me...

I tried every step at a time and many combinations, but only the succession of all steps at once made it! I hope I won't face this again...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Darkendorf
  • 463
  • 11
  • 28
14

Just for the other people who still have this problem and they have tried the above answers but still getting the error (which was my case), then my solution was to delete the project from Eclipse and re-import it again.

This made the Android library to be added again to my referenced libraries, so now I have two Android JAR files referenced, hence I deleted one of them and now it compiles fine.

Solution: Delete the project from Eclipse IDE and then re-import it again, then check for the above solutions.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mido
  • 504
  • 2
  • 6
  • 18
10

Ran into this problem myself today. Cleaning and rebuild did not fix the problem. Deleting and reimporting the project didn't help either.

I finally traced it back to a bad additions to my .class file. I think this was added by the plugin tools when I was trying to fix another problem, removing it got rid of the "Conversion to Dalvik format failed with error 1" build error:

<classpathentry kind="lib" path="C:/dev/repository/android-sdk-windows/platforms/android-3/android.jar">
    <attributes>
        <attribute name="javadoc_location" value="file:/C:/dev/repository/android-sdk-windows/docs/reference"/>
    </attributes>
    <accessrules>
        <accessrule kind="nonaccessible" pattern="com/android/internal/**"/>
    </accessrules>

Joe Fernandez
  • 4,781
  • 4
  • 26
  • 23
9

For me, an extra JAR reference had appeared in my build path. I deleted this, and it works now.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
brux
  • 3,197
  • 10
  • 44
  • 78
8

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.

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

Hope that will help you.

mvmanh
  • 151
  • 2
  • 4
8

My problem was caused by ADT version 12.0 and ProGuard integration. This bug is well documented and the solution is in the documentation

Solution is in here

ProGuard command line

Croc
  • 485
  • 5
  • 14
  • Thanks Croc, I do not think that bug is very well documented - I didn't find it after searching for an hour for a solution. – Kevin Sep 08 '11 at 16:54
  • You're probably write - the problem is that a single error message have too many causes. Google should have some more messages to help users outline the problem. You can get comfort in the fact it took me two days to resolve the problem when i encountered it... – Croc Sep 16 '11 at 06:34
  • Comment 11 on the linked bug discussion page solved the problem here: set build output to Verbose (from Window > Preferences > Android > Build) and look for JAR or classes that the compiler is using but shouldn't be there. Remove them. Experience build without any problem again. – Giulio Piancastelli Jul 06 '12 at 09:04
8

Updating Proguard to latest version solved it for me.

  • My proguard path was C:\Program Files (x86)\Android\android-sdk\tools\proguard\
  • I downloaded the new version from here
  • and replaced both bin and lib folders

THANK GOD!

onkar
  • 4,427
  • 10
  • 52
  • 89
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130
7

I found something else. Android uses the /libs directory for JAR files. I have seen the "Conversion to Dalvik format failed with error 1" error numerous times, always when I made a mistake in my JAR files.

Now I upgraded Roboguice to a newer version, by putting the new JAR file in the /libs directory and switching the class path to the new version. That caused the Dalvik error.

When I removed one of the Roboguice JAR files from the /libs folder, the error disappeared. Apparently, Android picks up all JAR files from /libs, regardless of which ones you specify in the Java build path. I don't remember exactly, but I think Android started using /libs by default starting with Android 4.0 (Ice Cream Sandwich, ICS).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Christine
  • 5,617
  • 4
  • 38
  • 61
7

In general, it seems that this problem comes when there are unnecessary JAR files in build path.

I faced this problem while working on IntelliJ IDEA. For me it happened because I added JUnit and Mockito libraries which were being compiled at runtime. This needed to be set to "testing" in module properties.

mindreader
  • 1,763
  • 1
  • 20
  • 35
  • Oh thanx for mentioning "In general, it seems that this problem comes when there are jars unnecessary in build path." After deleting the unnecessary jar files error is gone. :) – surendran Jun 15 '12 at 12:51
7

In my case the problem is actually with OpenFeint API project. I have added OpenFeint as library project:

library project]![1]![Enter image description here.

It is also added into build path, ADT tools 16 gives error with this sceneario.

Right click on your project and click build path, configure the build path and then see the image and remove your project OpenFeint from here and all is done :)

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AZ_
  • 21,688
  • 25
  • 143
  • 191
6

None of previously proposed solutions worked for me. In my case, the problem happened when I switched from referencing a library source code folder to using the library JAR file. Initially there was an Android library project listed under the Android application project Properties\ Android page\ Library section, and the library compared also in project explorer tree as a link to the library source directory.

In the first place, I just deleted the directory link from the project tree and I added the JAR library to the build path, but this caused the exception.

The correct procedure was (after changing back the build path and putting back the reference to the library source):

  • properly remove the library source directory link by actually removing the reference from application project Properties\ Android page

  • adding the library JAR to the application project build path as usual.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
superjos
  • 12,189
  • 6
  • 89
  • 134
6

None of the listed solutions worked for me.

Here's where I was having a problem:

I added the jSoup external JAR file to my project's path by first putting it in a source folder called "libs", and then right clicking on it, Build Path -> add to build path. This threw the Dalvik conversion error. It said I had "already included" a class from that JAR file. I looked around the project's directory and found that the place where it was "already included" was in fact the bin directory. I deleted the JAR file from the bin directory and refreshed the project in Eclipse and the error went away!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrew
  • 2,898
  • 4
  • 25
  • 23
5

In my case

project->properties->java build path -> in order and export tab -> uncheck android-support-v4.jar

Mufrah
  • 534
  • 7
  • 22
5

Just clean the project

If this does not work try the other solutions

Yassin
  • 1,376
  • 18
  • 18
5

This answer is basically what many people try to say, but many people may not understand. So...

"Another reason can be if you have a JAR file located somewhere in your project 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." answered Jan 2 '12 at 6:23 Rashmi.B

Meaning:

If you have for instance these two libraries (.jar) in your lib folder: Libraries (.jar) in your *lib* folder

and then these two folders are also added to your build path: Libraries in your build path

means that they are counted twice, thus giving you the error!

Solution:

  1. Remove these libraries from your build path AND remove "Android Dependencies" as well: Remove libs that are in your *lib* folder from the build path!
  2. Clean all projects
  3. Export you project
  4. Enjoy! :)
Tanasis
  • 795
  • 1
  • 9
  • 21
5

All the solutions above didn't work for me. I'm not using any precompiled .jar. I'm using the LVL and the Dalvik errors where all related to the market licensing library.

The problem got solved by deleting the main project and reimporting (create a new project from existing sources).

olivierg
  • 10,200
  • 4
  • 30
  • 33
5

I had the same problem and none of these solutions worked. Finally, I saw in the console that the error was due to duplicated class (one in the existing project, one in the added jar file) :

java.lang.IllegalArgumentException: already added: package/MyClassclass;
[2011-01-19 14:54:05 - ...]: Dx1 error; aborting
[2011-01-19 14:54:05 - ...] Conversion to Dalvik format failed with error 1

So check if you are adding jar with duplicated classes in your project. If yes, try removing one of them.

It worked for me.

Seynorth
  • 686
  • 2
  • 8
  • 22
5

Often for me, cleaning the project DOES NOT fix this problem.

But closing the project in Eclipse and then re-opening it does seem to fix it in those cases...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrew Mackenzie
  • 5,477
  • 5
  • 48
  • 70
  • 1
    Same for me, closing Eclipse and starting up again usually solves it. Then I get I try, but I cannot make a second export, I have to restart again. – Ted Feb 25 '13 at 23:55
5

I ran into this problem but my solution was twofold. 1.) I had to add an Android target version under project -> properties -> Android. 2.) I didn't have all google 'third party add-ons'. Click in AVD SDK manager under available packages -> third-party add-ons -> Google Inc. I downloaded all of the SDKs and that solved my issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
THE_DOM
  • 4,266
  • 1
  • 18
  • 18
  • My solution was pretty much the same as @THE_DOM 's solution. Right-click the project, choose Android Tools, then choose Add Compatibility Library. This will download those "third party add-ons" if you don't have them (THE_DOM's solution), but it will also add them into your project. Whether this solution is just a placebo or not is yet to be seen. :) – Chris Aug 17 '11 at 22:35
5

I am using Android 1.6 and had one external JAR file. What worked for me was to remove all libraries, right-click project and select Android Tools -> *Fix Project Properties (which added back Android 1.6) and then add back the external JAR file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jim Rhodes
  • 5,021
  • 4
  • 25
  • 38
5

I ran into this problem because the Android-Maven-plugin in Eclipse was apparently not recognizing transitive references and references referenced twice from a couple of projects (including an Android library project), and including them more than once. I had to use hocus-pocus to get everything included only once, even though Maven is supposed to take care of all this.

For example, I had a core library globalmentor-core, that was also used by globalmentor-google and globalmentor-android (the latter of which is an Android library). In the globalmentor-android pom.xml I had to mark the dependency as "provided" as well as excluded from other libraries in which it was transitively included:

    <dependency>
        <groupId>com.globalmentor</groupId>
        <artifactId>globalmentor-core</artifactId>
        <version>1.0-SNAPSHOT</version>
        <!-- android-maven-plugin can't seem to automatically keep this from being
             included twice; it must therefore be included manually (either explicitly
             or transitively) in dependent projects -->
        <scope>provided</scope>
    </dependency>

Then in the final application pom.xml I had to use the right trickery to allow only one inclusion path---as well as not explicitly including the core library:

    <!-- android-maven-plugin can't seem to automatically keep this from being
        included twice -->
    <!-- <dependency> -->
    <!-- <groupId>com.globalmentor</groupId> -->
    <!-- <artifactId>globalmentor-core</artifactId> -->
    <!-- <version>1.0-SNAPSHOT</version> -->
    <!-- </dependency> -->

    <dependency>
        <groupId>com.globalmentor</groupId>
        <artifactId>globalmentor-google</artifactId>
        <version>1.0-SNAPSHOT</version>
        <exclusions>
            <!-- android-maven-plugin can't seem to automatically keep this from
                being included twice -->
            <exclusion>
                <groupId>com.globalmentor</groupId>
                <artifactId>globalmentor-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.globalmentor</groupId>
        <artifactId>globalmentor-android</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • Strange thing for me was that `true` in the android-maven-plugin fixed the issue for `mvn install` but not for `mvn deploy` where I got the described error ... really strange – Karussell Nov 23 '13 at 10:09
4

In my case im having an exteranl jar added.So I moved the external jar position to top of android reference in Project Prop--->Java buildPath--->Project references

sha
  • 1,410
  • 2
  • 18
  • 37
4

I know it's answered already, but here was my solution:

My Android project was from a Subversion repository, and I just did Checkout as a New Project. I had to manually add my libraries (Android and Java) to the build path, otherwise it wouldn't let me compile. Then I would get the above error.

I had to make a new Android project, and then manually copy over the changes.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yuudachi
  • 2,266
  • 3
  • 17
  • 17
4

My problem was in integration of Ant + ProGuard + AdMob SDK library + Debug mode. I was building debug APK using Ant and Added AdMob SDK JAR to libs/ directory. Eclipse generated the debug APK normally, but Ant could not. I was getting the following error.

[apply] UNEXPECTED TOP-LEVEL EXCEPTION: [apply] java.lang.IllegalArgumentException: already added: Lcom/google/ads/AdActivity; [apply] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)

I also had ProGuard turned on for debug build in my build.xml (default is off):

<target name="-debug-obfuscation-check">
    <property name="proguard.enabled" value="true"/>
</target>

That was the problem. Somehow ProGuard and AdMob SDK do not live together in debug mode. ProGuard did not obfuscate AdActivity class so it appeared in bin/proguard/obfuscated.jar unobfuscated, but the same class exists in the AdMob SDK JAR file. Eclipse was building debug APK without ProGuard, so it worked fine.

So my solution was just to turn off ProGuard for debug builds in build.xml. I hope it helps somebody.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
smok
  • 1,658
  • 13
  • 13
4

None of the answers here helped in my case.

For me the problem was that mvn eclipse:eclipse was generating a classpath entry that was a project reference to an Android library project, however, it was not showing up in the Eclipse build path settings! This meant that the library classes ended up in the dexer twice, once from the hidden project reference, and once from the linked library JAR.

I had to open the .classpath with a text editor and remove the projects element manually. This fixed the issue.

mxk
  • 43,056
  • 28
  • 105
  • 132
3

I was using ADT r14 and when ever i tried adding any library project, I got this error. For me what worked was simply updating the ADT to the latest version. It solved the problem instantly. I tried almost all the workarounds given on stackoverflow but nothing else really worked for me.

Swati Rawat
  • 1,729
  • 1
  • 19
  • 34
3

I personally managed to fix this by manually editing the project.properties file within the Eclipse project.

What it was:

target=android-16
android.library.reference.1=..\\..\\github\\ActionBarSherlock\\library
android.library.reference.2=../../github/android-numberpicker/library

What I changed it to so the problem went away:

target=android-16
android.library.reference.1=../../github/ActionBarSherlock/library
android.library.reference.2=../../github/android-numberpicker/library

This file was not fixed automatically by using the "Fix Project Properties" tool.

gosr
  • 4,593
  • 9
  • 46
  • 82
3

For me the problem was that I had set the wrong compiler compliance level (1.8 instead of 1.7).

This answer solved it:

In the Project SDK section, when you add an Android SDK you should provide the Java SDK and all my Android SDKs uses Java 8 as SDK so it create the class files with the wrong version even if the Project level is 1.7 (i don't know why, i supposed that everything was choosed by Project level). Now i changed the SDK (the java version "1.x.0" part.)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Luigi04
  • 437
  • 5
  • 14
  • 1
    In 2018, stuck with a legacy app that *has to* be built with Eclipse Neon, the build failed with the Dalvik message. Very frustrating. The problem was that Neon installs with compiler compatibility at 1.8, and for the legacy app (api 19, 4.2.2) you must use compiler compatibility 1.7 (not compiler 1.7, compatibility 1.7). It was very frustrating to sift through the plethora of preferences to finally find the compatibility level. Upvoting this answer because it states what I did, and what you will have to do...IF you can find this answer (like I could not, I solved it on my own). Frustrating – Les Jul 17 '18 at 17:44
3

I had the exact same error with a project containing protobuf lite (Protocol Buffers by Google) in its classpath. I guess the reason was the protobuf-lite.jar that was in my classpath and project-folder was built in my previous machine. When I downloaded Maven and re-built the protobuf-lite.jar file then added it anew as a user-library to my project everything worked fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jubei
  • 1,686
  • 1
  • 17
  • 28
3

What worked for me are the following:

  • Clean the build completely
  • Removed the extraneous android.jar file that I found in Project/Properties/Libraries.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
leandroid
  • 11
  • 2
2

i am also faced this problem when i am add same jar file with different versions, i simply remove old version jar an clean the project it works fine for me.

Brajendra Pandey
  • 2,280
  • 1
  • 16
  • 22
2

In my case the issue was originated after updating Eclipse and ADT in March 2011. In my project I am using a JAR which was producing issues to rebuild and none of the former solutions worked. It took me some days to try all , search up&down with no satisfying solution. Apparently there was a double reference to the .jar file.

Finally I :

  1. removed any references from the libraries,
  2. deleted the physical file form within the application.
  3. got the .jar (located in a different directory outside of the project) using "Add External Jars"
  4. performed a project "clean",
  5. update references into the module calling the jar with (ctrl)+(shift)+O

and it did finally compile.

2

This error is due to

  1. having more than one JAR file.
  2. If the JAR file has similar class files, then .dx format cannot be parsed.

Solution:

  1. make and choose the appropriate JAR file.
  2. get the latest one.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joker
  • 715
  • 1
  • 14
  • 31
2

I am using ADT 7 and the other fixes didn't work (but I still did them).

Then I copied proguard.cfg from another project and simply pasted it into the older ADT project folder. And wallah, it worked.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

In my case, unplugging my phone from the USB was all it took to fix this error.

Nathaniel Jones
  • 1,829
  • 3
  • 29
  • 27
1

This usually happens to me after either eclipse has been running for a long time or after I have built a signed apk successfully.

As far as my experience with this is concerned, the fix it I just restart eclipse.

124697
  • 22,097
  • 68
  • 188
  • 315
  • Yep, for me, that seems the only solution as well. have tried many of the suggestions made in other answers but they didn't seem to work. it usually happens after already having the project 'Run as', 'android application' when you'r still working on it, and then exporting it. restarting eclipse and then straight away exporting works for me ! – Larphoid Mar 08 '14 at 14:40
1

I had the same error, and tried everything above but nothing helped me.

My projects are attached to GIT source control system, and I realized that there are some GIT related task while exporting to Andorid application. Then I commited all changes to the GIT repository and error dissapear.

So, if you are using GIT for source control and nothing above help you, try to commit all changes to the GIT repository (and eventually push to upstream) and try export again.

Goran
  • 76
  • 4
  • That helped me, thanks! unfortunately it seems that there is no general solution for that error. – Lukas Apr 29 '14 at 15:13
1

For NewRelic users:

If you have integrated the newrelic jar in your app, this happens when the newrelic version is outOf date.

Solution:

  • Update the newrelic jar to the latest version. On eclipse, its just right click on the project and update newrelic. Or you can download the new version directly.
amalBit
  • 12,041
  • 6
  • 77
  • 94
1

Just Project > Clean worked for me.

activesince93
  • 1,716
  • 17
  • 37
1

I had the same problem, when I tried to export my project. Nothing to see in the console.

For me the solution was upgrading proguard to the lastest version, hopes this helpes someone.

Dennis
  • 1,528
  • 2
  • 16
  • 31
1

I went through the steps in this answer and still did not get a resolution. I kept searching around online and found that you can get this error if you're trying to export an APK while an Android device is connected to the computer.

Disconnecting my device followed by closing the project, rebooting the computer, opening the project and cleaning it worked for me all three times this has happened.

Community
  • 1
  • 1
jakewp11
  • 450
  • 4
  • 11
1

The error should be finally fixed as of ADT 17/Tools r17 preview releases! At least some instances of it, if not all.

Artem Russakovskii
  • 21,516
  • 18
  • 92
  • 115
  • I can say that they aren't fixed. I'm getting them more under r20 than every before. I now regret upgrading. – Norman Sep 11 '12 at 16:03
0

None of these answers worked for me. My problem is caused by JUnit and hamcrest. See also java.lang.IllegalArgumentException: already added: Lorg/hamcrest/BaseDescription; Conversion to Dalvik format failed with error 1

Community
  • 1
  • 1
Bevor
  • 8,396
  • 15
  • 77
  • 141
0

it's better to include all *.jar files in the "lib" directory of the project folders tree. and in this way , you'll not need to define the build path by going to the properties of the project. "lib" is already a build path

0

I had the same problem. when i checked,i saw that there were 2 classes with the same name, 1 in each of the external jar file i had added. i had to then remove 1 of the jar file. Luckily i got another jar file for the 1 i had removed.

Nakul Sudhakar
  • 1,574
  • 1
  • 24
  • 24
0

If you are using Leadbolt ads SDK in you app and you are combining both "Notification ads" and "Display Ads" you need to use pubxappCom.jar instead of pubxapp.jar for notification ads, or you get this error!

Happy coding!

Nick
  • 1,393
  • 1
  • 14
  • 22
0

Google API on dependencies cause this problem. After remove it works well.

Ahmad
  • 437
  • 5
  • 20
0

I cleaned my main App Project AND the Android Library Project which it uses. Solved the issue

Lawrence Tierney
  • 856
  • 1
  • 12
  • 30
0

-Remove all your libraries from your java Build path. And add it again. - Clean your project.

Run it.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
0

This error was being caused for me due to several files I had excluded from the build path being deleted, but not removed from the exclusion list.

Project -> Properites -> Java Build Path -> Source tab -> project/src folder -> double click on Excluded -> Remove any files that no longer exist in the project.

InsanityOnABun
  • 5,973
  • 5
  • 21
  • 25
0

I found the solution in a differant way... https://stackoverflow.com/a/14948244/1014288

Thanks to this you can fix no deleting and stuff

Community
  • 1
  • 1
Mashiah
  • 111
  • 1
  • 6
0

In most cases this problem is caused by a buggy or corrupted version of Proguard, that for some strange reason often will be installed from official Android SDK manager

Don't edit Proguard bat file to avoid further problems, if you get this issue, download the latest stable version of Proguard from official site and replace all proguard files in

android-sdk\tools\proguard

with the latest proguard files extracted from the downloaded archive.

Make no sense remove all external libraries dependencies, if a developer add a library to his project most likely the library is needed.

Silverstorm
  • 15,398
  • 2
  • 38
  • 52
0

Nothing helped me, but the suggested solution here worked like a charm:

i.e. adding the line -optimizations !code/allocation/variable to proguard-project.txt

Rahul Sharma
  • 2,867
  • 2
  • 27
  • 40
ercan
  • 1,639
  • 1
  • 20
  • 34
0

Another case of android witchcraft, if nothing else works, try increasing your versionCode and versionName by 1 in the manifest.

It worked for me.

Josh
  • 6,251
  • 2
  • 46
  • 73
0

Hi Previously I had Android SDK Build tools 18.1.1 and Windows XP . then my app was running properly.

But I updated My system to Windows 7 and also updated Android SDK Build tools to 19 to have latest configurations.

But My project has xercesImpl-2.9.1.jar file so When I started to run my application with new/updated configurations I was getting

Conversion to Dalvik format failed with error 1 while parsing org/apache/xerces/impl/xpath/regex/ParserForXMLSchema.class

So I went through all the answers which are mentioned to this question but was not able to solve . I wondered for 4 days then I found this link which saved my life, after reading this I came to know that problem is due to xercesImpl-2.9.1.jar with Android SDK Build tools to 19.

So I downgraded it to Android SDK Build tools to 18.1.1. And I got rid of this problem.

i am posting my answer here so that if anyone would face this issue they can get solve it.

It made me frustated. Hope will help others.

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
0

I tried each and everything but nothing worked.

Interesting thing was if we export android application using proguard we were getting "conversion to dalvik format failed with error 1" error but if we don't use proguard while exporting then APK was successfully created.

Finally one of the jar in our android project was having a .class file with more than 1.5 MB size.Its size was causing this issue.We split that class into many smaller classes and problem went away.

2intor
  • 1,044
  • 1
  • 8
  • 19
0

Nothing worked for me here, i had to change my proguard file to add this line:

-keep class !mycode.** { *; }

which keeps any code thats not my package.

j2emanue
  • 60,549
  • 65
  • 286
  • 456
0

I have just installed newest eclipse with newest API and newest SDKs and tools but, years later, this error does not get old. I waste a day to figure it out. Tried everything. In vain. Because this message is very generic and a lot of different problems will raise it. So, solutions pointed by some will not work for others.

A good first approach is to go to Window > Preferences > Android > Build and UNCHECK 'Skip packaging and dexing...'. This way you will have more clues on your specific error when you are building, not only exporting.

In my case, I got an "Dx unsupported class file version...". This error I did not see reported here. Well, based on this I discovered that some old jars I use were compiled with 1.6 and others with 1.7. So I changed default IDE compiler compliance level to 1.6 (Window > Preferences > Java > Compiler), and after complete clean and rebuild of every dependence I had, I finally could generate my APK.

PFROLIM
  • 1,194
  • 9
  • 11
0

I had this problem with Eclipse neon and JDK 1.8. After changing to JDK 1.7 the problem was solved.

enter image description here

Eugen
  • 1,356
  • 12
  • 15
-1

None of the answers here worked for me either.

However, I could fix the error by removing the Android classpath container (in my case Android 4.4) from ALL attached libraries except the main application and then exporting the APK. The library projects won't compile anymore, but the jar file still exists and the APK is getting deployed. I'm not sure what's the reason for this behaviour.

TSGames
  • 679
  • 11
  • 25
-14

If you want to solve this problem then you have to change Android SDK1.6 to Android 2.2. After that, clean the project and then build and run. Then you will see that your application is running.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amit Thaper
  • 2,117
  • 4
  • 26
  • 49