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 ?

245 Comments.

  1. Thanks Man!!!

    It really works !!!

    Spend a day finding why app stopped working, until found your article.

    Thanks Again!!!

  2. Daniel (4 comments)

    OK…
    A new solution that also solves the requirement to move the libraries to “libs” folder.
    1. Add the jar as external jar (as you used to do it) with full path.
    2. Add all the jars to the “Export” (not used to do ).
    3. Move them to be the first items to be exported ( VERY IMPORTANT !!!)

    Enjoy

    Daniel

  3. many many thanks.
    It’s works for me

  4. Great explanation, but Daniel´s solution worked directly, Thanks :)

  5. DC (1 comments)

    Thanks a bunch!!!

  6. Rahul (1 comments)

    Thanks a lot!! :) been trying to figure out the solution for sometime now..

  7. hmkim (1 comments)

    thank you !!!! TT

  8. potter (1 comments)

    Hello,

    I did what you said Daniel but it didn’t work for me :(

    I didn’t add any external Jar and the referenced libraries (Android and google map) are in the Libs foldrt

  9. Rafael Saraiva Campos (1 comments)

    Thanks, guys!!! But Daniel´s solution worked just fine!!!!!

  10. Thanks, I also really did not understand Xavier’s blog post. The post from Daniel was also helpful. Xavier ought to link to this blog.

  11. Thank you very much !
    I had a hard time for the NoClassDefFoundError,
    so I appreciate your help very much.
    You’re a godsend?

  12. thank hundred times!

  13. Stephan Wiesner (1 comments)

    cool, thanks!

  14. Karthik (1 comments)

    just awesome!!!!!!!!!!

  15. Stan Kurdziel (1 comments)

    This stumped me as well. Even after project->clean, my project did NOT pick up the libs/*.jar as an Android Dependency. My target platform is google APIs 2.2 – api level 8.
    I was able to resolve this by temporarily switching the project target to Google APIs 4.0.3 API Level 15 (right clicking project, properties, Android, Project Build Target). After hitting ok, it added the Android Dependencies to the project, and then I switched back to the original target and they stayed around and the project built fine.

  16. Foxykeep (47 comments)

    @Jens : He did in fact in Google+ :)

  17. dan (2 comments)

    Ok, moving the libraries to the libs folder worked fine for me, but now I can’t attach the docs to it. Any idea?

  18. firelegna (1 comments)

    thanks. :smile:

  19. Thanks for posting this but that solution didn’t work for me. What did work was checking the checkbox for each library under “Order and Export”: See screenshot here: https://lh4.googleusercontent.com/70Yi716GL-yaDIWciXa_WEV3Dsy1zRGT0UePOQBQAYq8oz1xO-Vl1T8Mv5j3kFhRCDPkClk2JEYOez9JsyQ9_-OCt-KO9WFNy6YIUfWrWoewrD39Fp4

  20. Foxykeep (47 comments)

    @Marvin Paul: What you describe is the second solution at the end of my post :)

  21. Doh! Not sure how I could have missed that. Feel free to delete my comment.

  22. Foxykeep (47 comments)

    It’s late so it happens ^^

  23. Mohammed Sameer (1 comments)

    Thanks a million :)

  24. Leonard (1 comments)

    :shock: :shock: :shock: :shock: THANKS! it worked! :grin:

  25. AVEbrahimi (1 comments)

    Thank you, it worked and saved my time! :razz:

  26. Ammoula89 (1 comments)

    thx a lot it worked :grin:

  27. Thanks FoxyKeep for starting the thread, but I used DroidUX Team’s answer since I only use the external admob jar. I have to say it makes me not want to upgrade eclipse since something is always changing and causes a day or two to find out how to fix it!

  28. Thx a lot. It works for me.

  29. me (1 comments)

    Thanks so much! If I had found your post several hours ago, I would feel like a younger man now.

  30. Andrés Moreno (1 comments)

    Thank you so much for your great help…

  31. Thanks too much, thanks. It works. I am so happy now.

  32. hityou05 (1 comments)

    :razz: thanks man!!

  33. dila (1 comments)

    Daniel, u are awesome
    thanks a lot…….

  34. Markus (1 comments)

    Thanks so much!
    Especially Daniel’s tip to move the external libraries in the export tab at the first position was the key for my app to work again.
    This saved my whole week!

  35. Thanks a lot!!!

  36. Felipe (1 comments)

    Phew, thanks for the help!

  37. Jared (1 comments)

    Thank you! I spent all day trying to figure this out. Works perfectly.

  38. amaldona (1 comments)

    Thanks a lot!!!! You save me
    That was a extremely weird error.

  39. jacob-chen (1 comments)

    thanks a millious , i have bean upsetted by this problem for several days. I fixed it now. ClassNotFound is no longer be my problem

  40. tommy (1 comments)

    dude!!!! i love u man!!!!! i spent the whole day today trying to figure out why my app kept crashing, thanks!!!!!!

  41. nice solution ! :grin:

  42. Thanks so much for posting that tip to rename “lib” to “libs”.
    This was driving me insane after updating to rev19 :evil:

  43. Alex (1 comments)

    muchas gracias!!, excelente información, me saco de apuros

  44. Rodger (1 comments)

    Thank you very much! I love you!

  45. Thanks for the help. Been trying to get the Eclipse/Phonegap app to show up on my Droidx or the Emulator for about a month.

  46. Keith Humphrey (1 comments)

    Thanks for the help. That was driving me nuts.

  47. Saks (1 comments)

    Thanks Man, you saved my day!

  48. :mrgreen: THANKS man. It worked! changed lib to libs. (Many hours later)

  49. Tom (1 comments)

    I’m running ADT 18 and wasn’t getting a NoClassDefFoundError, but I was getting a java.lang.RuntimeException error with a very similar error stack as the one above. Checking all the references in the “Properties > Java Build Path > Order and Export” solution worked for me.

    Thanks!

  50. ars_art (1 comments)

    thanks man,you saved me

Leave a Reply

Trackbacks and Pingbacks:

Page optimized by WP Minify WordPress Plugin