last day (15 days later) » 

5:39 PM
0
A: Android JNI with dlopen() instead of system.loadlib

Alex CohnNo you cannot use JNI if you don't use System.loadLibrary() or equivalent.

 
Is it possible to write a loader library, load that with system.loadlibrary; then based on some runtime variables from java use that lib to do the dlopen and have possibly two instances of the required library at runtime?
 
Yes it is possible. You are looking for a way to keep some global variables separate? They may get obscured by one another
 
Yes, since they are two distinct processes, there should be a way to load the .so so that they don't collide. I am now loading a wrapper lib, then writing some code to create two handles, that are opened with this command: dlopen("/data/app-lib/app.name/libWantedLib.so", RTLD_NOW); I am not sure if this will be the same as calling system.loadlibrary() and I was hoping to get some insight before going too far down this path only to end up where I started. Not only that, it seems that androids dlopen() doesn't support that many flags.
 
If you use a lib in two separate processes, you don't have what to worry about to begin with: each can load it own library with System.load() or ldopen() and be completely isolated from the other.
On the other hand RTLD_GROUP is not supported on Android, therefore you cannot use two libraries with exported symbols that have same names.
 
I should've wrote this down here. The problem that I am facing is that I load a .so library in my onCreate(); function. For the first instance of the service I see the typical loading lib: Trying to load lib /data/app-lib/org.libsdl.app-1/libSDL2.so 0x42495a50 | Added shared lib /data/app-lib/org.libsdl.app-1/libSDL2.so 0x42495a50, etc... On the seconds instance of the service, in the onCreate function instead of loading the lib again it says already found ..../libSDL2.so at address 0x...... and returns that one. At which point my app breaks. Any possible solution?
 
5:39 PM
Your app breaks - how exactly? Do you get a crash? One possible problem could be that the same Java objects are accessed from two different threads. You can try to put such variables in thread local storage.
 
I'd like to avoid this: loading library SDL2 Trying to load lib /data/app-lib/org.libsdl.app-1/libSDL2.so 0x428b4ee8 Shared lib '/data/app-lib/org.libsdl.app-1/libSDL2.so' already loaded in same CL 0x428b4ee8 As you can see when the service loads the shared library on the first launch everything is fine. When the service is launched again, the shared library is already loaded and it gets linked. That's where the trouble happens.
 
What is not clear to me why "is already loaded" is wrong for you. But maybe you want to start two services as separate processes?
 
That doesn't really help me solve the issue at hand
 
6:04 PM
What is this "issue at hand"? I saw some vague hints here and there, but I still don't understand what two copies of the libSDL2 in memory will resolve
 
6:17 PM
SDL library has a thread that runs a loop and maybe some global variables.
Once libSDL is in memory, if I try to load another instance of libSDL and it returns the first instance any SDL calls that I make will affect this previous thread and cause the whole thing to fall apart
I can't change the way the SDL lib is made, I was looking for a way to load multiple instances of the shared library so that they can run different instances. I can choose when to load the sharedlibrary programatically but I cannot figure out how to either have 2 versions of the shared library or some other work around
 
6:38 PM
So, why using separate processes does not solve the issue?
 
it's a wallpaperservice.engine, how can i use separate processes?
 
7:18 PM
but how do you use more than one service?
 
thanks for your help, please don't bother replying anymore.
 
Have you tried android:isolatedProcess in AndroidManifest?
 

last day (15 days later) »