194

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?

5
  • 1
    How did you added the jar file? Did u added using build path -> Libraries -> External jars?? Feb 11, 2010 at 21:55
  • 1
    Right-clicking project > Build Path > Add External Archives... as per instructions here: scoreninja.appspot.com
    – Tom R
    Feb 11, 2010 at 21:57
  • 4
    If you updated ADT recently, then look at John's answer below (and upvote it!) stackoverflow.com/a/9916751/489852
    – Atul Goyal
    Apr 4, 2012 at 13:57
  • 1
    If 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.
    – Carlos P
    Jul 14, 2012 at 7:33
  • Did you try multidex ? Oct 24, 2015 at 8:53

27 Answers 27

235

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.

8
  • 1
    Thanks 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.
    – Hong
    Mar 31, 2012 at 11:32
  • Thanks John! I will add that after changing folder to libs I had to restart eclipse for it to work. Apr 11, 2012 at 23:17
  • 5
    I 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.
    – Travis
    Jun 3, 2012 at 1:17
  • 1
    I 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.
    – Snowwire
    Jul 5, 2012 at 20:54
  • Hi. 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
    – Jono
    Aug 24, 2012 at 15:04
100

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)

6
  • Thanks 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.
    – Luis
    Jun 12, 2012 at 19:58
  • 5
    Does 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?
    – Lou Morda
    Jul 24, 2012 at 16:11
  • I had this problem after updating ADT and this solved it for me. Jul 28, 2012 at 5:51
  • 5
    It helped me, but only after I did Project -> Clean
    – altumano
    Oct 5, 2012 at 18:55
  • Thanks!! Saved me. Had to do a clean and restart after installing Eclipse Juno.
    – Rynardt
    May 22, 2013 at 11:40
68

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
7
  • ScoreNinjaAdapter 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
    Feb 11, 2010 at 21:58
  • The error literally just happens here: sna = new ScoreNinjaAdapter(this, SN_APP_ID, SN_APP_KEY);
    – Tom R
    Feb 11, 2010 at 22:03
  • Do you need an import statement for external jar files? I have never used them. Feb 11, 2010 at 22:09
  • Have you tried with the removing the .jar file from the assests folder approach? Feb 11, 2010 at 22:32
  • Yeah. 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.
    – Tom R
    Feb 11, 2010 at 22:34
48

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" />
0
27

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 :)

1
15

I'm not sure if this is related, or if you're even still looking for an answer, but I came across this thread while trying to research the same error (but possibly for different reasons).

I couldn't find any solutions online, but an answer on a similar thread got me thinking and realized I probably just needed to rebuild (or clean) the project.

In Eclipse, go to Project => Clean. Select your project and Eclipse seemed to fix it itself. For me this solved the problem.

Hope this helps.

1
  • Yeah 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.
    – Timmmm
    Nov 29, 2012 at 16:28
13

I have encountered the same issue. The reason was that the library that I was trying to use had been compiled with a standard JDK 7.

I recompiled it with the -source 1.6 -target 1.6 options and it worked fine.

2
  • THANK 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 :( Sep 1, 2013 at 13:29
  • I 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. Sep 26, 2014 at 10:35
7

Same thing worked for me: Properties -> Java Build Path -> "Order and Export" Interestingly - why this is not done automatically? I guess some setting is missing. Also this happened for me after SDK upgrade.

3

Right click your project folder, look for Properties in Java build path and select the jar files that you see. It has worked for me.

3

John O'Connor is right with the issue. The problem stays with installing ADT 17 and above. Found this link for fixing the error:

http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

2

I tried everything from this post (and some other posts), and it didn't worked for me, this is by far the most terrible ADT upgrade I have experienced, and I will never upgrade without a working ADT backup.

I managed to solve it by removing the project, and then adding it again using a source backup I had.

2

I had this same error with ADT22. Resolved it checking "Android Private Libraries" in properties -> Java build path -> Order and export. If you are using any library projects, the same should be done for them as well.

1
  • It also worked for me. I included the library but forgot to check it in "Order and export". Thank you!
    – jmrodrigg
    Nov 13, 2013 at 11:35
2

All the existing answers don't work for me because my case is a little bit different. It took me a few hours to get it to work. I'm using Eclipse.

My android project includes another normal java 1.6 project, which needs a 3rd party jar file. The trick is:

  • include the jar in the normal java project for it to compile (only), don't check it in the "Order and Export" tab
  • also copy this jar file into the "libs" folder of the android project so it'll be available in runtime

Hope this help those who have similar scenarios like mine.

1

sometimes you have to take the whole external project as library and not only the jar:

my problem solved by adding the whole project (in my case google-play-services_lib) as library and not only the jar. the steps to to it (from @style answer):

  1. File->New->Other
  2. Select Android Project
  3. Select "Create Project from existing source"
  4. Click "Browse..." button and navigate to the wanted project
  5. Finish (Now action bar project in your workspace)
  6. Right-click on your project -> Properties
  7. In Android->Library section click Add
  8. select recently added project -> Ok
1

Sometimes it will happen due to not including jar, which you have dependency, with "uses-libary" tag in your AndroidManifest.xml.

Also, make sure it should be inside "application" tag.

Regards,

Ravi

1

I had this problem and it was caused by not "exporting" the library.Issue was just because the .class files for some classes are not available while packaging the APK.Compile time it will work fine with out exporiting

In my case I was using "CusrsorAdapter" class and under "JavaBuildPath->Order and Export" I didn't check the support V4 jar.Once it is selected issue is gone.

To make sure you are getting noClassDefFound error because of above reason, please check your logacat, you will see unknown super classs error at run time.

1

Acutally you have reached the infamous 64k limit issue, you need to enable multidex.

This is how you do it. https://developer.android.com/tools/building/multidex.html

0

I tried various things and the reason for error in my case was conflict between maps.jar and Google Api in Java Build Path-> Libraries. So, when i removed the maps.jar it worked fine.

Regards,

wahib

0

please make sure your jar file is in the libs directory of your project in you are using newer ADT version with your eclipse.

0

I got the exact same problem ... To fix it, I just removed my Android Private Libs in "build path" and clicked ok ... and when i opened op the "build path" again eclipse had added them by itself again, and then it worked for me ;)...

0

i spent two days trying to solve this issue after updating ADT. finally i was lucky to get this post here:

https://code.google.com/p/android/issues/detail?id=55304

which led me in the right direction. when you follow the solution - remember to replace the android support library of all your projects to the same version (remove it and re-install it to the projects). i hope this helps - good luck

0

If you prefer to know which files the workaround is related to here's what I found. Simple change the .classpath file to

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

Replace the .classpath file in all library projects and in main android project. The .classpath file is in the root folder of the eclipse project. Of cause don't forget to add your own classpath entries, should you have any (so compare with your current version of .classpath).

I believe this is the same result as going through the eclipse menus as componavt-user explained above (Eclipse / Configure Build Path / Order and Export).

0

The solution here worked for me. It's a matter of importing the library to the libs folder, then modifying the build.gradle file and then cleaning with gradlew.

0

If you change your order and export in your project build path, this error will not occur. The other way of achieving it is through .classpath in your project folder.

0
0

Try this:-

Step 1

Add all the libraries to build pat in Eclipse( means make all libraries referenced libraries)

Step 2

Delete R.java file and again build the project. Don't worry, R.java will automatically get recreated.

Chill :)

0

As i understood, your Project shows no errors, because you included the Jar. But the Jar won't be used, when your Project got "exported" to the device. Try this

Project -> Properties

Java Build Path / Order and Export

[✔] Your Jar

0

This happens quite very often to me.

Last time that happened I can remembered was caused by switching the Eclipse ADT (Google special edition) to Android Studio, and switching back. I basically tried all methods that I can found on stackoverflow which didn't work for me.

Eventually, I got the app working again (no more NoCalssDeffoundError) by switching my IDE to original Eclipse (Kepler) with ADT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.