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 ?

210 Comments.

  1. Doesn’t work.

  2. Foxykeep (42 comments)

    What exactly doesn’t work ?

  3. Thanks, interestingly in my project it does not contain the lib or libs folder, but I was able to use the export for the jars that I was having trouble with. They happen to the twitter4j and json-lib-2.2.2. I appreciate the help.

  4. It worked…. thanks alot…

  5. susan (1 comments)

    Thanks a lot ! it worked !

  6. thanks, very helpful.

  7. Pablo (1 comments)

    Was this naming policy change really necessary Google?

  8. Rohit Garg (1 comments)

    Hey! do you know any solution for NetworkOnMainThreadException? I am not able to over rid of it.

  9. Foxykeep (42 comments)

    Starting with Jellybean (I think), you can’t do network operation in the main thread.

    You can either use an AsyncTask to do it if it’s a short operation. Otherwise you can check my library to use REST webservices in your application : http://www.datadroidlib.com

  10. Riccardo (1 comments)

    GRAZIE ….FUNZIONA….avanzi un caffè :-)

  11. I did exactly what you say and still get noclassdeffounderror

  12. it works …. again

  13. liutao (1 comments)

    thanks a lot,it worked.

  14. Ayan (1 comments)

    its not working….

  15. Solution don’t work for me either.
    I added a jar to the libs folder. It had everything I needed.
    I saw it appear in the Android dependencies.
    Source code had no errors.
    When checking on Order and Export tab of build path, jar was there.
    Cleaned.
    Restarted eclipse.
    Cleaned it again.
    Still receiving the java.lang.NoClassDefFoundError: hu.droidium.diet_futar_core.Test
    I’m using 21.0,0 on Windows.

  16. Forgot to tick in notify me of comments. Now I will get notified.

  17. Will (2 comments)

    Did anyone still having this issue find a solution? I added my jar to the libs folder, it appears in Android Dependencies, but I still get error. I have tried many different ideas, and nothing seems to be working. Compiles, but fails at runtime.

  18. Rev@ (1 comments)

    Thanks yar really helpful after a day i get rid from this .:)

  19. Sabyasachi (1 comments)

    thanks..

  20. Faizan (1 comments)

    doesn’t work on adt 21 any help?

  21. I have jar dependecy problem with android app on eclipse 3.7.2, android sdk version is 19. For jar files I put them in libs filder. error:
    03-27 14:00:28.566: W/dalvikvm(699): Link of class ‘Lorg/red5/server/net/rtmp/BaseRTMPHandler;’ failed

    I check android Dependencies path is “org/red5/server/net/rtmp/BaseRTMPHandler”
    I don’t know why when android-pugin link jar file, it add extra character “L”?

  22. Foxykeep (42 comments)

    @faizan Did you follow exactly the guide ? I just tried on ADT 21 and it works without issues.

    @martin the L is just an information about the link. it is added for every element.
    Stupid question but are you sure that the class is in the jar ? You can also try to remove and add again the jar ? Also doing a full clean of the project may help

  23. Evass (1 comments)

    Thanks! it work!

  24. AdaVerayo (1 comments)

    Hello!

    I tried to follow your guide. However, I still have the problem. Here is my question on stackoverflow http://stackoverflow.com/questions/15821772/salesforce-enterpriseconnection-class

    I am using ADT 21.

    Could you help?

  25. Thank You….

  26. Thomas KJ (1 comments)

    Thank you so much!!! Saved me after 2 hours of debugging/googling :)

  27. Khurram (1 comments)

    Hurrrah……….
    That worked for me ………
    thnx……….

  28. chandu (1 comments)

    thank’s

  29. suri (1 comments)

    superb & powerful solution.. you made my job easy..Thanks

Leave a Reply

Trackbacks and Pingbacks:

Page optimized by WP Minify WordPress Plugin