NoClassDefFoundError on external library project for Android

Fu86 picture Fu86 · Nov 3, 2011 · Viewed 20.9k times · Source

I use eclipse for Google Android development.

I've created a library project ([x] Is Library in the Android-settings), which includes an external jar-file (Referenced Libraries). This library project are referenced in another Project (the actual project which will use the library project). This is done by add the project under the Android-settings.

the source compiles but if I want to execute it on the device, I get the NoClassDefFoundError for a class which is inside the jar-file which is included in the library project.

Edit: The jar-file ist added to the exported entries ([x] my.jar on the Order and Export-Tab from the library project)

Is there a clean way to get this working?

Answer

yorkw picture yorkw · Nov 3, 2011

It has been clearly stated in offcial API here:

A library project can include a JAR library

You can develop a library project that itself includes a JAR library, however you need to manually edit the dependent application project's build path and add a path to the JAR file

The jar lib must be manually added to the dependent application project's build path, not only the library project build path itself.

Update from SDK r17:

This is automatically handled by ADT now, check out new feature for ADT 17.0.0 release here:

Added feature to automatically setup JAR dependencies. Any .jar files in the /libs folder are added to the build configuration (similar to how the Ant build system works). Also, .jar files needed by library projects are also automatically added to projects that depend on those library projects. (more info)