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. markt (1 comments)

    Thanks! That did the trick. I too found myself reading “Dealing with dependencies in Android projects” on tool’s site, but it didn’t help me. There’s a bigger headache hidden with this: a lot of Android “starter” projects for Eclipse from various API’s may break too.

    Regards,
    Mark

  2. Primoz (1 comments)

    Tnx for this!

  3. Thanks for the quick fix!

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

  5. gzo (1 comments)

    I updated my SDK and ADT to the 17 version and I had a problem. when i open eclipse appears many errors!!
    “Initializing Java Tooling”.
    java.lang.NullPointerException

    parseSdkContent failed
    java.lang.NullPointerException

    Parsing Data for android-X failed
    java.lang.NullPointerException

    and i cannot open some projects.And i cant see xml graphical layout.!! how to fix it? help

  6. Monkey (1 comments)

    This can resolve reference jar problem,but how to resolve reference project ,For example:
    I create a java project and a Android project
    in the build path of Android project ,I add the java project for reference, then Android project use a class of java project cause NoClassDefFoundError , How to fix ?,thank you!

  7. Ha, I just stumbled upon the remixjobs podcast, clicked on the link to your blog, and realized that I was here yesterday, because I had the same problem than you. Coincidences are fun.

    Thank you anyway, this post really helped me.

  8. Foxykeep (47 comments)

    Monkey : Try to use the second solution with the export feature. Otherwise export a JAR from the first project (not the best but it will work)

    Thibault : Hehe ! Happy to help !

    Gzo : I don’t have the solution for your problem. Never had this one … Search on Stackoverflow. Maybe somebody had it there.

  9. QFAN (3 comments)

    I have a Robotium test project with a main project, run by ANT + Jenkins.

    Now with the R17, tests cannot run because all JAR libraries in the main project are not built into the test target. NoClassDefFoundError.

  10. Jamael Tanveer (1 comments)

    Thanks for the solutions! :grin:

  11. Foxykeep (47 comments)

    QFAN : keep your libraries like before and try to use the export way. It might work.
    Otherwise go to Google+ and ask Xavier Ducrohet if he has a solution

  12. QFAN (3 comments)

    Foxykeep: Thanks for reply. But I don’t have “Properties > Java Build Path > Order and Export” in my cmd.exe window.

    I’m digging through the android-sdk\tools\ant\build.xml but still have no hope finding out what’s going on.

    The interesting thing is, if I run through ant script, it says it can’t find a library referenced by the Target project. But if I run from Eclipse, then it complains that another library referenced by the Tester project cannot be find.

    BTW, eclipse doesn’t add “Android Dependencies” to the tester project, but only the Target project.

  13. QFAN (3 comments)

    So I made a simple project and its test project. This time Eclipse can run it but ant still gets NoClassDefFoundError. I attached the projects to http://code.google.com/p/android/issues/detail?id=27608

  14. Morgan (1 comments)

    Thank you SO MUCH!

  15. Foxykeep (47 comments)

    Maybe contact Xavier on Google+ and link your bug. He may have a solution for you

  16. Thank you! I was worried about this for a bit and I’m really glad it’s not user error entirely.

  17. sharan (1 comments)

    error resolved but no ads are showing.
    activity loads as normal

    please help

    using android 3.2

  18. Serge (1 comments)

    Thanks a lot!
    I got mad trying to fix error.

  19. Galtran (1 comments)

    many thanks! I killed half a night on it, Yesterday..

  20. Sebastian (1 comments)

    :?: I use Properties-BuildPath-Libraries-AddVariable to add JARs as Variable libraries, making it easier to handle update like admob and Flurry and easier to share my sources over different systems by Dropbox. But obviously this doesnt work anymore? Why? Adding a Variable is offered in the menu, worked fine sine long time and now? Hope we will get that fixed some day …

  21. Shawn (1 comments)

    Thanks for this article I was banging my head on the table trying to figure out WTF was wrong. This new update is hellish so many issues of the start/.

  22. Kurt Bugeja (1 comments)

    Works perfectly! I can’t believe how gurus at Google didn’t think of automatically applying these fixes instead of relying on developers to figure out the problems afterwards :???:

  23. Daniel (4 comments)

    Thanks for the solution…
    but it’s really idiot …
    If I have a library that I use in many projects I have to make “copies” of it in each project !!!!
    Why ????
    I want to have only one copy and be able to compile everything in one click with the new version…

    I will be glad to get a solution …

    Thanks

    Daniel

  24. worked (1 comments)

    Fix is not working. Not matter what I try, I continue to get the error:
    03-25 14:37:07.014: E/AndroidRuntime(1800): java.lang.NoClassDefFoundError: com.google.android.apps.analytics.GoogleAnalyticsTracker

  25. Foxykeep (47 comments)

    Did you add the GA lib to the libs folder ?
    Is the library appearing in the Android Dependencies ?

    Otherwise try the 2nd solution.

  26. Great post – this solved a lingering issue I’ve been having with Eclipse all day. :)

  27. Paul Drummond (1 comments)

    Thanks so much for writing this – I was completely stumped when my app suddenly started throwing ClassNotFoundExceptions when run on my device until I read this article. :-)

  28. Girish (1 comments)

    Excellent !! Thank you very much

  29. change_ty (1 comments)

    :razz: :razz: :razz: ????????thx a lot !!! this bug almost make me crazy…

  30. Maximiliano Poggio (1 comments)

    I have a problem.. after i upgrade to adt 17 i have a problem with ksoap2 library.

    I got the following problem:


    03-26 12:34:58.439: E/dalvikvm(1143): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method net.ShamanOperativo.ShamanOperativoActivity.webService

    I dont know whats happenning, i always add external jar ksoap2 in java build path and all was working.. and besides i dont have a “lib” folder in my project.
    When i add the library it appears on “Referenced Libraries”. what can i do ?? thanks

  31. Avishai (1 comments)

    Thank’s man!!
    Working on it for two days!!

  32. David Saurel (1 comments)

    Thanks for your help :-)

    Google shoulds better communicate regarding changes in android project structure.

  33. Foxykeep (47 comments)

    Maximiliano : Just add the ksoap library to a libs folder and it will be ok. You need to have your library appear in Android Dependencies and not in Referenced Libraries

  34. Raafat Said (2 comments)

    I followed the fix steps but when I try to run my app I get the following error:
    Conversion to Dalvik format failed with error 1

  35. That helped a lot. Thanks!

  36. Raafat Said (2 comments)

    Thank you Foxykeep, that helped.

  37. Derp (1 comments)

    Thanks a lot, that was driving me nuts.

  38. Jeremy (1 comments)

    Thanks a lot. I had been very embarrassed because of this problem. :razz:

  39. Daniel (4 comments)

    Hi

    Did someone find another solution except copying all the libraries to “libs” folder ?
    I have to many applications to work in this way… Please help ….

    Thanks

    Daniel

  40. Foxykeep (47 comments)

    Daniel : check the 2nd solution at the end of my post. It may be ok for your applications

  41. Daniel (4 comments)

    Hi

    Thanks and I already tried … and it’s not working :sad:

    Daniel

  42. Foxykeep (47 comments)

    Arf :/

    For my projects I use the libs solution so I don’t know about the other one. Try to contact the DroidUX team as it’s them who gave me this solution. They may have more info about it

  43. Sam (1 comments)

    Thanks. This way do work greatly!

    But i get another problem. How could i browse source code of jar file?
    Before ADT 17, i could attach source file from workspace but..now i can’t find the button any more.

  44. Foxykeep (47 comments)

    Sam : I have no idea … :o Ask Xavier or ask on stackoverflow if somebody knows. I didn’t know about this feature so … :) If you find an answer, I’d love to know it :)

  45. Tom Gardiner (1 comments)

    Mine works if I compile in debug, but fails if I use Proguard, which is very annoying!

  46. Menion (1 comments)

    Daniel
    I suffer in same way as you. Non of solutions works for me. Export of libs in Order and Export tab do not move them from “Reference libraries” to “Android Dep…” … damn Google updates. It’s everytime same …

  47. Serand (1 comments)

    One tip: exporting all my Eclipse User Libraries didn’t work until I put “Android Dependencies” BEFORE my libraries in the Order and Export tab.

    I never understood what the order was, but it sure do something :D

  48. Patryk (1 comments)

    Thanks a lot! :smile:

  49. Joan Pujol (1 comments)

    Does someone be able to use a test projects with external libraries and run it from eclipse?

Leave a Reply

Trackbacks and Pingbacks:

Page optimized by WP Minify WordPress Plugin