In my Android application in Eclipse I get the following error.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already add
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).
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...
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.
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\bin
and \gen
from project folder.classpath
file in root project foldereclipse -clean
Import
projectProperties
> Java Build Path
> Libraries
and remove everything else than Android XX.Y
clean
project, wait for automatic Building or Build
itI 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...
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
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.