NoClassDefFoundError - Eclipse and Android

JavaAndroidEclipseAntBuild

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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 - Java

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 - Java

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 - Java

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 - Java

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

Solution 6 - Java

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.

Solution 7 - Java

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.

Solution 8 - Java

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.

Solution 9 - Java

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.

Solution 10 - Java

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

Solution 11 - Java

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.

Solution 12 - Java

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.

Solution 13 - Java

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.

Solution 14 - Java

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

Solution 15 - Java

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

Solution 16 - Java

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.

Solution 17 - Java

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

Solution 18 - Java

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

Solution 19 - Java

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

Solution 20 - Java

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 ;)...

Solution 21 - Java

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

Solution 22 - Java

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

Solution 23 - Java

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.

Solution 24 - Java

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.

Solution 25 - Java

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

Solution 26 - Java

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

Solution 27 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTom RView Question on Stackoverflow
Solution 1 - JavaJohn O'ConnorView Answer on Stackoverflow
Solution 2 - JavaTillView Answer on Stackoverflow
Solution 3 - JavaAnthony ForloneyView Answer on Stackoverflow
Solution 4 - Javabrian.clearView Answer on Stackoverflow
Solution 5 - JavaAndrew KrizhanovskyView Answer on Stackoverflow
Solution 6 - JavaBrianView Answer on Stackoverflow
Solution 7 - JavaassyliasView Answer on Stackoverflow
Solution 8 - JavavladView Answer on Stackoverflow
Solution 9 - JavazachariaView Answer on Stackoverflow
Solution 10 - Javauser1555123View Answer on Stackoverflow
Solution 11 - JavaEliView Answer on Stackoverflow
Solution 12 - JavaprijupaulView Answer on Stackoverflow
Solution 13 - JavaGolden ThumbView Answer on Stackoverflow
Solution 14 - JavadvrmView Answer on Stackoverflow
Solution 15 - JavaRavi PanditView Answer on Stackoverflow
Solution 16 - JavaSojan P RView Answer on Stackoverflow
Solution 17 - JavaAshish RawatView Answer on Stackoverflow
Solution 18 - JavaWahib Ul HaqView Answer on Stackoverflow
Solution 19 - JavasamirView Answer on Stackoverflow
Solution 20 - JavapkdkkView Answer on Stackoverflow
Solution 21 - JavaRonView Answer on Stackoverflow
Solution 22 - JavaarbergView Answer on Stackoverflow
Solution 23 - Javagabr10View Answer on Stackoverflow
Solution 24 - JavageekgugiView Answer on Stackoverflow
Solution 25 - Javauser1606195View Answer on Stackoverflow
Solution 26 - Javauser3060608View Answer on Stackoverflow
Solution 27 - JavatyolabView Answer on Stackoverflow