[java] NoClassDefFoundError - Eclipse and Android

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?

This question is related to java android eclipse ant build

The answer is


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.


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


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.


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


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


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.


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


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


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

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.


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

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.


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

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.


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.


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


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


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.


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.


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


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


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


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.


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.


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


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.


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)


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to ant

How to create a signed APK file using Cordova command line interface? This compilation unit is not on the build path of a Java project Error executing command 'ant' on Mac OS X 10.9 Mavericks when building for Android with PhoneGap/Cordova How to execute Ant build in command line adding comment in .properties files Ant if else condition? Using FileUtils in eclipse How to put a jar in classpath in Eclipse? JAVA_HOME does not point to the JDK How to set ANT_HOME with Windows?

Examples related to build

error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' WARNING in budgets, maximum exceeded for initial How can I change the app display name build with Flutter? Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0) Still getting warning : Configuration 'compile' is obsolete and has been replaced with 'implementation' Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details Component is part of the declaration of 2 modules Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven