One thing that has continued to frustrate me as I learn Android development (via Eclipse) is getting Android app projects that reference Android library projects to work reliably. Sometimes the app project won't build because of missing class references that are defined in the library, and sometimes it builds but then crashes at runtime with the class defined in the library is referenced, with an error link
java.lang.NoClassDefFoundError: com.dave.customviewtestlib.LibTestClass
shown in by logcat.
I'm using Android Developer Tools Build: v21.0.1-543035
I've created a workspace with the simplest possible Android app project referencing the simplest possible Android library project. How exactly am I supposed to tie them together in Eclipse? They both build fine by themselves. Then I edit the "Java Build Path" of the Android app project. The confusing thing is, there seems to be a lot of ways to reference the library project. Sometimes one way works, then it stops working and another way that didn't work before starts working. Am I supposed to
- In the app project's Java Build Path | Projects, "Add" the library project, or
- In the app project's Java Build Path | Libraries, "Add Jar" and point to to a .jar containing the library's classes and other resources, or
- In the app project's Java Build Path | Libraries, "Add Class Folder" and point to the library project's "bin" folder which contains the classes, or
- In the app project's Java Build Path | Source, "Add Folder" and point to the library project's source folder, or
- Something else?
Also, there is the mysterious Java Build Path | Order and Export tab. What does that mean?
Also I have a related question: are these so-called Android libraries like static libraries (you reference them at build time and the code gets sucked in, and at runtime it is just part of the app binary), or like dynamic libraries (they can get installed separately on the device)? I understand it's all Java and all classes are loaded at runtime by the class loader, but I think there is still an important distinction. Most tutorials and references are so dumbed-down, getting answers is hopeless.
Any help would really help minimize my irritation :)