views:

66

answers:

1

I am developing a library for Android applications which does not use native code (JNI). I have tried suppling the library as an external jar in my Android projects but this method does not include the library contents in the apk and thus throws class not found errors when run in the emulator or device. I have also tried creating the library as an Android project in itself and this does work, but only for public static properties (not methods). With the library and application both being in separate apk's I can see that the VM notices references to the library and can read some properties, but when an attempt to instantiate a class in the library is executed I get class not found even though I can read the public static properties from it (very frustrating!!).

I realize that Davlik byte code is not the same as Java byte code but I am having trouble even finding good information about how to solve what would seem to be a very simple issue in Android. I am looking into the old PlatformLibrary stuff right now but I am not convinced this will work either since the sample has been removed from the Android site :(

So help me out if you can, if I find the answer before this happens I will share it.

viva la Android!

+3  A: 

I have tried suppling the library as an external jar in my Android projects but this method does not include the library contents in the apk and thus throws class not found errors when run in the emulator or device.

Put the JAR in your libs/ directory, and it will automatically be included in the APK.

This sample project from one of my books shows using the BeanShell JAR this way. Also, all of the GitHub repos starting with "cwac-" on my GitHub page are projects designed to build JARs to be included in Android projects via the libs/ directory.

CommonsWare
I just recently found out that this is one way to do it per-project, but it does not allow for the same type of sharing that the Text-to-Speech libraries use.
Mondain
Then try remote services via separate APKs. Or content providers via separate APKs. Or broadcast `Intents` via separate APKs. Or modify the firmware and build your own device with your own libraries in it. The `PlatformLibrary` is for modifying the operating system, through C/C++ and JNI, which is precisely what your question's subject says you do not want.
CommonsWare
Yes, PlatformLibrary doesn't work for us in this case and I think and Intent may be the way we have to go.
Mondain