NoClassDefFoundError - Eclipse and Android
Solution 1
I had this problem after updating ADT.
I was storing all of my JAR files in a folder called "lib" and adding the jars to the build path the normal Eclipse way. This worked fine until my update.
After my update, I was getting the NoClassDefFoundError for a class that I could clearly see was included in the jar (checking out the ReferencedLibraries classes).
The solution was to remove my jars from the build path and rename my "lib" folder to "libs". This is an ant convention, and seems to be the way the new ADT finds and includes libraries in an .apk file. Once I did this, everything worked fine.
Solution 2
I didn't have to put the jar-library in assets or lib(s), but only tick the box for this jar in Properties -> Java Build Path -> "Order and Export" (it was listed before, but not selected)
Solution 3
By adding the external jar into your build path just adds the jar to your package, but it will not be available during runtime.
In order for the jar to be available at runtime, you need to:
- Put the jar under your
assets
folder - Include this copy of the jar in your build path
- Go to the export tab on the same popup window
- Check the box against the newly added jar
Solution 4
I had this for MapActivity. Builds in Eclipse gets NoClassDefFound in debugger.
Forgot to add library to manifest, inside <Application>...</Application>
element
<uses-library android:name="com.google.android.maps" />
Solution 5
I have changed the order of included projects (Eclipse / Configure Build Path / Order and Export). I have moved my two dependent projects to the top of the "Order and Export" list. It solved the problem "NoClassDefFoundError".
It is strange for me. I didn't heard about the importance of the order of included libraries and projects. Android + Eclipse is fun :)
Related videos on Youtube
Tom R
Good times with C, Java, Python on web and embedded devices.
Updated on October 19, 2020Comments
-
Tom R over 3 years
I'm having a problem trying to run an Android app which, up until adding a second external library to its build path, was working fine. Since having added the scoreninja jar, I now get a NoClassDefFoundError when I try to run the app.
Here's the message:
02-11 21:45:26.154: ERROR/AndroidRuntime(3654): java.lang.NoClassDefFoundError: com.scoreninja.adapter.ScoreNinjaAdapter
As all of the build scripts are generated by the Android tools (?), I'm not sure what else I can do other than cleaning and rebuilding or restarting eclipse (I have already tried all three). Does anyone know how I can amend this?
-
Teja Kantamneni about 14 yearsHow did you added the jar file? Did u added using build path -> Libraries -> External jars??
-
Tom R about 14 yearsRight-clicking project > Build Path > Add External Archives... as per instructions here: scoreninja.appspot.com
-
Atul Goyal about 12 yearsIf you updated ADT recently, then look at John's answer below (and upvote it!) stackoverflow.com/a/9916751/489852
-
Carlos P almost 12 yearsIf you're having this issue, before you jump right into John's answer, @Till 's answer below is solving it for a lot of people too, myself included.
-
Ashish Rawat over 8 yearsDid you try multidex ?
-
-
Tom R about 14 yearsScoreNinjaAdapter is someone else's code, but I would be very surprised if it contained such an error as it is in common usage. The error happens at a point in my own code.
-
Tom R about 14 yearsThe error literally just happens here: sna = new ScoreNinjaAdapter(this, SN_APP_ID, SN_APP_KEY);
-
Anthony Forloney about 14 yearsDo you need an
import
statement for external jar files? I have never used them. -
Anthony Forloney about 14 yearsHave you tried with the removing the .jar file from the
assests
folder approach? -
Tom R about 14 yearsYeah. In the end, I got fed up with all this and just downloaded the source and copied the source files into my project. Not the nicest solution, but it works now. Thanks for all your help.
-
The Student almost 14 years@Anthony so I can't add another project to mine? I mean, because I can't add the whole project to the assets folder..
-
Hong about 12 yearsThanks a lot! I had neither a lib or a libs folder before yesterday's ADT update, and everything worked fine. After the update, all external jars had this problem. They have been fixed thanks to your answer. I have to combine yours with Brian's to make it work.
-
Michaeldcooney about 12 yearsThanks John! I will add that after changing folder to libs I had to restart eclipse for it to work.
-
navicore almost 12 yearsthx for this. placing my jar in assets/libs rather than just libs got the runtime working.
-
Travis almost 12 yearsI ran into the same problem after updating ADT, but I was keeping my jars in a directory outside my project and including them as a User Library in my build path. The solution was to remove the user library from my build path and instead include jars using "Add External Jars", and then make them exported by checking the checkboxes on the "Order and Export" tab.
-
Luis almost 12 yearsThanks so much! I had been struggling with this error for a long time and all I needed to do was check the darn box for the jar in the "Order and Export" screen. Funny thing is that I only had to do this so that it would work on a Nook Tablet emulator. Did not have a problem on devices or other emulators.
-
Snowwire almost 12 yearsI was referencing android-support-v13.jar as an external library at C:\android-sdk-windows\extras\android\compatibility\v13. I moved that JAR into the project libs folder and removed the reference from Java Build Path -> Libraries. A clean build and I was going again.
-
Lou Morda almost 12 yearsDoes anyone know why you have to do both, add the library and also select the checkbox in Order and Export? Is there a reason why I would want to add an external JAR but not include it in the Order and Export?
-
charles young almost 12 yearsI had this problem after updating ADT and this solved it for me.
-
Jono over 11 yearsHi. i tried our approach by adding the external jar libs inside /libs and now i recieve this error: Conversion to Dalvik format failed with error 1
-
NioShobu over 11 yearsHey, @Travis, I followed your solution, as I was referencing a custom version of the android.jar file (which had an extra class we are planning to use for coverage purposes). However, that custom class is giving me the NoClassDefFoundError, and that solution didn't seem to help. Also, because it is an Android Test project, there doesn't appear to be any lib or libs folders...
-
John O'Connor over 11 years
-
altumano over 11 yearsIt helped me, but only after I did Project -> Clean
-
Timmmm over 11 yearsYeah there seems to be a bug in Eclipse/ADT/dex/whatever that basically misses out classes in the build. It can also miss out the
Application
class which leads to a different error. -
Rynardt almost 11 yearsThanks!! Saved me. Had to do a clean and restart after installing Eclipse Juno.
-
arberg almost 11 yearsThis is also the solution mentioned by the second usercomment here in the bugruport: code.google.com/p/android/issues/detail?id=55304
-
Hendy Irawan over 10 yearsTHANK YOUUUUUUUUUUUUUUU!!!!!!!!!!!!!!!!!!! I've been frustrated by this problem and you solved it! It's a bit ironic that even the latest Jelly Bean 4.3 SDK (API 18) still cannot read 1.7 JAR/classes. And worst of all it doesn't complain at all :(
-
jmrodrigg over 10 yearsIt also worked for me. I included the library but forgot to check it in "Order and export". Thank you!
-
Pranav Mahajan almost 10 yearsIf your JARs are already in "libs" folder then most probably @Anthony Forloney's answer will work for you.
-
Pedro Náñez over 9 yearsI was having the same problem. The worst of all is that I thinked in this option and then I changed my -source 1.7 with -source 1.5 (to be sure) and the problem wasn't solved. But, after read your comment, I tried again with 1.6 and then, it worked like a charm.
-
Marcel Verwey over 9 yearsAfter checking the box I also had to move the jar file to the top in the "Order and Export" screen. But the strange thing is, after moving it to the bottom again it still works!