“Conversion to Dalvik format failed with error 1” on external JAR

前端 未结 30 2516
抹茶落季
抹茶落季 2020-11-21 07:32

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

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already add

相关标签:
30条回答
  • 2020-11-21 08:04

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

    0 讨论(0)
  • 2020-11-21 08:04

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

    0 讨论(0)
  • 2020-11-21 08:05

    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.

    0 讨论(0)
  • 2020-11-21 08:06

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

    0 讨论(0)
  • 2020-11-21 08:08

    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
    
    0 讨论(0)
  • 2020-11-21 08:09

    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.

    0 讨论(0)
提交回复
热议问题