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. Doesn’t work.

  2. Foxykeep (47 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 (47 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 (47 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

  30. haneen (1 comments)

    it doesn’t work for me, still have NoClassDefFoundError
    I have both android dependencies and Referenced Library in my project

  31. I just wanna say, the final update you wrote fixed my problem :)

  32. LittleNicholas (1 comments)

    i did this and now eclipse crashes (after during compile) instead of my application in my mobile…
    f*ck you google..

  33. AB (1 comments)

    Hola It works pretty well.

  34. Otávio (1 comments)

    Funcionou perfeitamente.

    Muito Obrigado!

    Obs: não esqueça de reiniciar o Eclipse após ad configurações acima.

  35. Ladair (1 comments)

    Thank you. You saved my life.

  36. Andres Perez (1 comments)

    Greetings.

    Already tried to follow this, and other suggestions to this issues. But still, I’m not making it to work. I posted a question in StackOverflow. Would you check it and see if you can help me?

    http://stackoverflow.com/questions/16971106/exporting-jar-to-use-in-unity-with-3rd-party-libs-included-noclassdeffounderro

    Thanks in advance

  37. Mafalda (1 comments)

    Thank you.. It worked =D

  38. I removed the library “Android Dependencies” for my mistake, as I put it again? help please!

  39. Salvuccio (1 comments)

    THANK YOUUU! You saved my day!!

  40. xdung (1 comments)

    Thanks. it helped me :)

  41. Mark (2 comments)

    Awesome. Worked great. Thank you.

  42. Thank you for posting this solution. It didn’t work for me, but the information provided helped me get my project working again… It was missing 1 step :)
    After doing the steps in the original post, the jar should be in the libs folder in eclipse.

    The missing step to get it working (for me) was:
    Right click on the project name > Properties > Java Build Path > tab Libraries -> Add JARs…
    In the JAR selection dialog that pops up:
    Double click your project -> double click libs -> select the jar you need and click OK.
    The jar should now be listed again on the libraries tab.

    Now perform the step in the update of the original post:
    Click the Order and Export tab and click/check the checkbox next to the jar you just added.

    That’s it… after doing this, I could finally run again…

  43. Harry Bosch (1 comments)

    FIXED: Similar problem after I recently upgraded to Android ADT 22, Java 1.7 and eclipse Kepler.

    Tip: Check which Java version you used to compile the jars you’re including.

    Background

    I had refactored a package in my Android project, i.e. removed it from my Android Project and created as a stand-alone jar because I need to deploy it to an other machine also.

    Then I compiled the new stand-alone project (under standard Java 1.7 environment).

    I added the library using Properties | Java Build Path | Libraries | Add Library | User Library etc.

    I also ensured that I’m exporting the new library to the Android device:

    Properties | Java Build Path | Order and Export (tick the library).

    I recompiled my Android project and I got the same problem.

    I recompiled my standalone jar using Java 1.6 compatibility (rather than 1.7). Dalvik doesn’t like 1.7.

    No need to add to lib or libs at all. Works fine using this method.

    Regards
    Harry

  44. Deu certo! Só faltou colocar que assim que eliminar todas as bibliotecas exigidas no TUTO, teria que fechar , e re-abrir o ADT pra ele recarregar novamente.

  45. Oblomov (1 comments)

    Thanks a lot.

  46. Hi,
    All of the fixes like this mention Eclipse, but is there a related fix for Android Studio?
    The way it adds files doesn’t seem to be the same…

    Thanks,
    Phil

  47. Foxykeep (47 comments)

    First release of Android Studio was shipped with ADT19. So you cannot have this problem with it.

  48. Stefano (1 comments)

    How do I export the references in Android Studio?
    I have this problems, too!

  49. Foxykeep (47 comments)

    If I understand right, you tried to go from Eclipse with a version of ADT before 17 directly to Android Studio ?
    If that’s the case, I’ll do the upgrade to a version of ADT superior to 17 inside eclipse first by following this tutorial. Then I’ll do the migration to Android Studio. That should fix it. No idea how to do the fix in Android Studio directly…

  50. fallak (1 comments)

    i dont have dependencies folder what to do ?

Leave a Reply

Trackbacks and Pingbacks:

Page optimized by WP Minify WordPress Plugin