“Conversion to Dalvik format failed with error 1”

2018-12-31 01:20发布

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 the possible solution, but none of the possible solutions work. I even tried to change to Android 1.6 instead of 1.5 (the current version I use).

30条回答
看风景的人
2楼-- · 2018-12-31 01:37

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.

查看更多
低头抚发
3楼-- · 2018-12-31 01:38

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.

查看更多
旧人旧事旧时光
4楼-- · 2018-12-31 01:38

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

查看更多
还给你的自由
5楼-- · 2018-12-31 01:39

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
查看更多
梦醉为红颜
6楼-- · 2018-12-31 01:40

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>

查看更多
看风景的人
7楼-- · 2018-12-31 01:40

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.

查看更多
登录 后发表回答