How to fix the “NoClassDefFoundError” with ADT 17

So I updated my SDK and ADT to version 17 and once again I got a big problem :)

Every project I have which use JAR libraries could still be built without problems but as soon as they start on the phone, they crashed with the following error :

03-21 19:20:56.455: E/AndroidRuntime(24471): FATAL EXCEPTION: main
03-21 19:20:56.455: E/AndroidRuntime(24471): java.lang.NoClassDefFoundError: org.acra.ACRA
03-21 19:20:56.455: E/AndroidRuntime(24471): at com.foxykeep.myproject.HomeActivity.onCreate(MyProjectApplication.java:127)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3925)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread.access$1300(ActivityThread.java:122)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.os.Looper.loop(Looper.java:137)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-21 19:20:56.455: E/AndroidRuntime(24471): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 19:20:56.455: E/AndroidRuntime(24471): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 19:20:56.455: E/AndroidRuntime(24471): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-21 19:20:56.455: E/AndroidRuntime(24471): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-21 19:20:56.455: E/AndroidRuntime(24471): at dalvik.system.NativeStart.main(Native Method)

I asked Xavier Ducrohet and Tor Norbye (both working on the ADT plugin) on Google+ about the error and they linked to this page which explains how to solve the problem but is not ultra clear (at least for me).

So here is the same solution but explained with screenshots so we can see more easily what changed  :

From left to right, we have :

  • My project with ADT 16 (the small graphic changes are due to the fact the left image is from Eclipse Windows while the 2 on the right are from Eclipse Mac)
  • My project with ADT 17 before the fix
  • My project with ADT 17 after the fix
We can see :
  • In blue, the changes due to the patch (more info on this at the end of this post)
  • In red, the changes for the fix

What I did to fix the bug was :

  • Remove the libraries from the standard Java build path :
    • Right click on the project name > Properties > Java Build Path > tab Libraries > remove everything except the “Android X.X” (2.3.3 in my case) and the “Android Dependencies”
  • Rename the libraries folder from “lib” to “libs”
    • By doing that, all the libraries in the folder “libs” are found by the Android plugin and are added to the “Android Dependencies” item of the project
  • Clean the project (not exactly needed)
  • You are good to go !

This problem is due to the fact that libraries are not managed the same way with the new ADT build.
Instead of having 2 different managements of libraries (one for Android Library Projects, one for the standard jars), now both are merged into the Android Dependencies item.

Other info, the annotations.jar file is for the new lint Java annotations (more info here : http://tools.android.com/recent/ignoringlintwarnings)
Besides this small problem, the ADT version 17 looks really good and I love the new things added to the lint checks !!

[Update]

The DroidUX Team found another solution to fix the problem. I didn’t test it personally but it don’t see why it shouldn’t work : 

Hi,

Just to add to the solution:

If you have references to jars that are not in the ‘libs’ folder, for example if you use ‘classpath variable’, you can resolve the NoClassDefFoundError issue with the new ADT 17 by exporting the references.

To export the references: simply go to “Properties > Java Build Path > Order and Export”, and check all the references you want exported.

Cheers,

DroidUX Team

[/Update]

Similar Posts:

Leave a comment ?

247 Comments.

  1. jeno (1 comments)

    You made my day sir

  2. Mona Thakur (1 comments)

    Thank U so Much…
    I was trying from last 2 days but could not find solution.
    After making changes my project ran successfully thank u once again and keep posting………..

  3. chris (2 comments)

    Legen— wait for it —- dary!!

  4. chris (2 comments)

    Legen —- wait for it——- dary!!

  5. Manuel (1 comments)

    Thanks, thanks, thanks, thanks, thanks… :eek:

  6. broken_droid_again! (1 comments)

    oh how i hate :evil: these updates….

    ok, more to the point — the ‘export’ solution worked for me. But not the renaming one (it was already libs).

    Thanks!

  7. Miruna (1 comments)

    for me is not working :cry:

  8. Lev (1 comments)

    it doesn’t work!

  9. GeorgeV (1 comments)

    Many, many, many, THANKS!

  10. lib is now libs-

    THANK YOU for posting this solution I had a feeling it would take a lot longer than 1 minute to fix.

    :lol:

  11. Dan (2 comments)

    Works… thanks for the fix!

  12. max (1 comments)

    thanx a milli

  13. Raghavendra (5 comments)

    doesn’t work *sob* :’(

  14. Rakesh Patil (1 comments)

    It does work… thanks a lot…
    i was hitting my head for last 2 days…

  15. Raghavendra (5 comments)

    Hey,
    I am on ADT 18 now. I did everything exactly as you said. My project also looks just like yours in the screenshot. But why does it still give the error? If you want, I will attach the screenshots of my project and Build Path and I will also attach my ‘log cat’. Please do something to help me. I have been struggling with it for 4 days now :sad: :cry:
    Thanks in advance.

  16. Foxykeep (47 comments)

    Can you show me a screenshot of your project hierarchy ?
    And did you try to clean your project ?

  17. Raghavendra (5 comments)

    here is the screenshot :

    here is the code snippet where the error occurs:
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme(“http”, 80, PlainSocketFactory.getSocketFactory()));
    ClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);

    If you need the log, I will send that too.

    Any help would be highly appreciated. Thank you very much.

  18. I am sorry, I dont think the link to the image appeared in the previous comment. Hope I attached it properly this time.

  19. Haresh (1 comments)

    Thanks DroidUX Team….It worked..

  20. hoanvn (1 comments)

    many thanks to you !!! :mrgreen:

  21. bungie (1 comments)

    simple solution…brilliantly put across…thanks :smile:

  22. dekela (1 comments)

    Raghavendra , Did you manage to solve this with ADT 18?

    I am still getting:
    E/dalvikvm( 8489): Could not find class ‘winterwell.jtwitter.Twitter’, referenced from method com.example.yamba.StatusActivity$1.run
    W/dalvikvm( 8489): VFY: unable to resolve new-instance 27 (Lwinterwell/jtwitter/Twitter;) in Lcom/example/yamba/StatusActivity$1;
    D/dalvikvm( 8489): VFY: replacing opcode 0×22 at 0×0000
    D/dalvikvm( 8489): DexOpt: unable to opt direct call 0x001b at 0×06 in Lcom/example/yamba/StatusActivity$1;.run

  23. Raghavendra (5 comments)

    Dekela,
    No. I did not manage to solve the problem with ADT 18 and I am very disappointed with it. I could not use these jars, so I had to use deprecated methods in my application and I do not have a good feeling about it! If you manage to come across a solution yourself, pleeaaaase let me know. I will be terribly grateful.
    Thanks,
    Raghavendra.

  24. thanks, really helpful. save my day. I using ADT 18 :mrgreen:

  25. Shushu (2 comments)

    New ADT, new problems ?
    Just upgraded to ADT 20 (for the new Google Cloud Messaging library), and voila – back to “could not find class” problems…
    Anyone else seen this ?

  26. Foxykeep (47 comments)

    Can you give more information about this specific issue ? Librairies used, target SDK, model and android version of the test phone.

    Also can you send me the stacktrace and your project (or a sample project) so I can try to reproduce it ?

  27. Shushu (2 comments)

    I didn’t get back to you since somehow the problem disappeared and I wasn’t able to reproduce.
    What I did was to change android build output to verbose (don’t think it is relevant…) and rearranged the android dependencies list to put the “problematic” classes on top of the list.

    I hope it won’t happen again, but if it will I promise to get back to you…

  28. itcropper (1 comments)

    holy SMOKES! I tried everything and this finally worked. after deleting all of my .jars, I had to go in and change the paths for all the .jars in the libs folder though. Either way though, it works!

  29. Dirk Bruere (1 comments)

    That bastard update cost me days of work. Thanks for solving it.

  30. zhudonghe (1 comments)

    Thank you so much!!!!

  31. gggg (1 comments)

    many thanks, you saved me !

  32. summit (1 comments)

    exporting referenced jars worked for me! thanks! XD

  33. samths (1 comments)

    @Rghvendra :This thing worked for me.
    1. Go to build path remove all external .jar files
    2. create folder libs in your project and place your jtwitter.jar file to that folder.
    3.you should now able to see that jar under Android dependencies in your project.
    clean the project and run it

  34. Avinash (1 comments)

    Hi,
    I m trying to develop an app on AndEngine till now it was working fine but when i took update it started to give such error and still error persists after doing the following steps as above please help !!!!!!!!!!!!

  35. Alvaro (1 comments)

    You saved me :D

    Thank you!!!

  36. Following the above instructions was not sufficiant.
    I had to right click on my project and select “Android Tools ” / “Fix Project Properties” from the contextual menu

  37. Man! You are the beast!!!

  38. Joe (1 comments)

    You sir, are fantastic. :)

  39. gjdspy (1 comments)

    Excelent! it works fine!

  40. You saved me!!

  41. Derrick (1 comments)

    It worked! Thank you!!!

  42. hari (1 comments)

    thnk u ..its working…

  43. juanPh (1 comments)

    adt21 just paste the AndEngine.jar to libs folder and its good to go

  44. thanks! I finally got it right!

  45. Sobia Awan (1 comments)

    Its not working for me:)

  46. Thank so much! I lost 5 hours because of this issue!! Finally resolved just addig “libs” folder!
    How is it posible that just a little update, in this case ADT they forget about developers!!!

  47. Foxykeep (47 comments)

    They didn’t forgot about the developers. it’s just that the previous system allowed you to do something wrong like having your libraries in “lib” while the common usage is to put them in “libs”.

  48. Thanks! This helped a lot.

  49. Sahil (1 comments)

    thank you very much….your reply of of real help!!!

  50. Thank you so much sir…

Leave a Reply

Trackbacks and Pingbacks:

Page optimized by WP Minify WordPress Plugin