Search code examples
androidjarnoclassdeffounderrorlibs

Adding a JAR into the Android project's /libs folder


There are tons of questions about this, but none gives a clear solution to this problem (is it really so difficult?)

I'm trying to add a jar to my Android project. Since r17, Google says we should add the jars to /libs folder, and that the andriod tools will take care of the rest.

I have included a very big library, and it works good, except of one class, so I decided to try and make my own jar.

I created a new java project, and added a simple Test class. Then I exported it as a jar and manually copied the jar into the /libs folder. I cleaned and rebuilt my android app without problems, but at runtime, referencing the Test class, i get the following errors:

java.lang.NoClassDefFoundError: mytestpackage.Test

When I include the source of the jar into my project directly, it works (of course).

So what am I doing wrong?


Solution

  • Well, after struggling with it for a day now, I found out that I had the compiler level set to 1.7 in the library project, so when I exported the jar, it was exported with a higher compiling level than what android supports (1.6).

    So the solution, in the project of the jar to export: Properties -> Java Compiler -> Enable specific settings -> Compiler compilance level -> 1.6

    That fixed it for me, I hope it's useful.