csdnceshi65
larry*wei
采纳率0%
2010-04-21 06:47 阅读 734

在外部 JAR 上"转换到 Dalvik 格式失败,错误1"

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

转载于:https://stackoverflow.com/questions/2680827/conversion-to-dalvik-format-failed-with-error-1-on-external-jar

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

29条回答 默认 最新

  • 已采纳
    csdnceshi56 lrony* 2012-01-18 05:36

    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.

    点赞 24 评论 复制链接分享
  • csdnceshi78 程序go 2012-01-18 05:36

    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.

    点赞 26 评论 复制链接分享
  • csdnceshi70 笑故挽风 2012-01-18 05:36

    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

    点赞 10 评论 复制链接分享
  • weixin_41568131 10.24 2012-06-10 15:04

    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.

    点赞 10 评论 复制链接分享
  • weixin_41568196 撒拉嘿哟木头 2012-01-18 05:36

    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>
    

    点赞 9 评论 复制链接分享
  • weixin_41568183 零零乙 2012-01-18 05:36

    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

    点赞 9 评论 复制链接分享
  • csdnceshi52 妄徒之命 2012-01-18 05:36

    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.

    点赞 9 评论 复制链接分享
  • weixin_41568184 叼花硬汉 2015-01-11 14:49

    Just clean the project

    If this does not work try the other solutions

    点赞 9 评论 复制链接分享
  • csdnceshi71 Memor.の 2012-01-18 05:36

    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.

    点赞 8 评论 复制链接分享
  • csdnceshi56 lrony* 2012-04-23 13:32

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

    点赞 8 评论 复制链接分享
  • csdnceshi74 7*4 2012-10-19 05:55

    In my case

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

    点赞 8 评论 复制链接分享
  • weixin_41568196 撒拉嘿哟木头 2012-01-18 05:36

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

    点赞 7 评论 复制链接分享
  • weixin_41568134 MAO-EYE 2012-01-18 05:36

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

    点赞 7 评论 复制链接分享
  • csdnceshi58 Didn"t forge 2012-01-18 05:36

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

    点赞 7 评论 复制链接分享
  • csdnceshi77 狐狸.fox 2012-01-18 05:36

    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!

    点赞 6 评论 复制链接分享
  • csdnceshi80 胖鸭 2012-01-18 05:36

    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.

    点赞 6 评论 复制链接分享
  • csdnceshi72 谁还没个明天 2012-01-18 05:36

    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.

    点赞 4 评论 复制链接分享
  • csdnceshi80 胖鸭 2012-01-18 05:36

    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.

    点赞 4 评论 复制链接分享
  • csdnceshi77 狐狸.fox 2012-01-18 05:36

    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.

    点赞 4 评论 复制链接分享
  • weixin_41568126 乱世@小熊 2012-01-18 05:36

    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!

    点赞 4 评论 复制链接分享
  • weixin_41568183 零零乙 2013-08-28 09:30

    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.

    点赞 4 评论 复制链接分享
  • csdnceshi76 斗士狗 2014-09-18 06:10

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

    点赞 4 评论 复制链接分享
  • csdnceshi64 游.程 2012-01-18 05:36

    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>
    
    点赞 3 评论 复制链接分享
  • csdnceshi62 csdnceshi62 2013-06-26 19:08

    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

    点赞 3 评论 复制链接分享
  • csdnceshi61 derek5. 2014-06-15 15:10

    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.

    点赞 3 评论 复制链接分享
  • csdnceshi71 Memor.の 2012-01-18 05:36

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

    点赞 2 评论 复制链接分享
  • csdnceshi70 笑故挽风 2012-01-18 05:36

    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.

    点赞 2 评论 复制链接分享
  • csdnceshi52 妄徒之命 2012-02-20 07:05

    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

    点赞 2 评论 复制链接分享
  • csdnceshi51 旧行李 2012-03-08 09:32

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

    点赞 2 评论 复制链接分享

相关推荐