0

I am trying to reference a Java and an Android library (that I created) to use within my Android application built in Eclipse.

I am referencing the Java library via Properties-->Java Build Path-->Projects-->Add.
I am referencing the Android library via Properties-->Android-->Library-->Add.

Both of these are shown within the windows after adding them. I also moved the Java library to the top of the list within Properties-->Java Build Path-->Order and Export.

My project compiles fine but when I run the application on my device I get a NoClassDefFoundError from the Java library. The class is in there and should work.

Did I miss something that I need to link in order to get this running correctly?

1
  • well make sure that your library in the same level where your project is located,for instance both of your library and project should be in the same workspace Commented Jun 4, 2013 at 13:59

1 Answer 1

1

I am referencing the Java library via Properties-->Java Build Path-->Projects-->Add.

This is incorrect. Please undo that, and then copy the JAR into libs/ within your project. If you are on the R22 or higher version of the tools, you may also need to go to "Order and Export" in your build path dialog and check "Android Private Libraries".

What you did only added the JAR to the compile path. Putting the JAR in libs/ will add it to the compile path and package the JAR's contents in your APK, so those classes are available at runtime.

Sign up to request clarification or add additional context in comments.

4 Comments

It just added the JAR to the libs folder, and checked "Android Dependencies" within the build path dialog and am still getting the NoClassDefFoundError. I am not too sure what else I can try besides adding these libraries directly into the android application.
@Matt: I said to check "Android Private Libraries", not "Android Dependencies", if you are on the R22 tools.
It must be new in R22? I will update and get back to you. Thanks for the help so far though.
@Matt: "It must be new in R22?" -- yes. Just having the JAR in libs/ is sufficient on previous versions of the tools. Make sure you have fully rebuilt the project (e.g., Project > Clean in Eclipse).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.