Consider the following situation: I have two android projects named P1 and P2 which both produce an apk which use the same process-id and will run in the same process on android.
P1 and P2 both use Java library JL1. JL1 loads at runtime shared library1 SL1.
What I see runtime is that at some point I get a java/lang/UnsatisfiedLinkError while loading this SL1.
It also outputs: Shared lib already opened.
What causes this problem? I’m assuming that library code in java is sort of copied in every project/apk and at runtime when apks are merged in one process it forgets about the copies. So every copy loads its shared library itself, causing the already loaded error.
If so, isn’t this unwanted behaviour. Because, now you can never have a java library with an shared library in the same process used more than once.
[edit] I found out that every apk uses its own class loader (also when in the same process). This means that every JL will be class loaded per apk and therefore every shared object will be loaded more than once, resulting in an error. Somebody any ideas how to get around this? Is it possible to let apks share a classloader?
Every apk has its own class loader. This means that two projects/apks will have there own copy of classes from the library. Which they load at runtime. Therefore what looks like the same classes are actually copies. Therefore loading a native library in such a class will result in loading it for every loaded class (even if this is done in the static field). Which results in a runtime error for loading the native shared object more than once if the two apks share the same process.