Hi!
I’m not entirely sure what’s needed to load a shared library on Android, but I was able to try it on iOS recently. Note that I had to codesign all binaries. However, on iOS, it’s still not allowed to release with more than one binary (the main executable)
"…as a simple resource"
What type is this? Did you put it in as a bundle resource or as an Android resource? It shouldn’t matter really, they should both end up within the apk (verify the location by unzipping the apk)
As for the original task, supporting shared libraries, I think bundle resources and native extensions helps with this. I’m uncertain what extra features would be needed to support this? This case is a good example.
One thing I recall with last time I used java to load libraries (in bob.jar), it was really tricky because the top library file was dependent on another library file. Eventually, what I did was this.
- Find the library file
- Add the parent folder of the file, to the java path’s
- jna.library.path, java.library.path
- Load the dependency
- Lastly, register the library
Here is some code to show the flow (Desktop platforms):
public class MyLoader {
static void addToPath(String variable, String path) {
String newPath = null;
// Check if the property was set externally.
if (System.getProperty(variable) != null) {
newPath = System.getProperty(variable);
}
if (newPath == null) {
// Set path where the library is found.
newPath = path;
} else {
// Append path where the library is found.
newPath += File.pathSeparator + path;
}
// Set the concatenated jna.library path
System.setProperty(variable, newPath);
}
static {
try {
File lib = new File("the path to the library on disc");
String libPath = lib.getParent();
addToPath("jna.library.path", libPath);
addToPath("java.library.path", libPath);
// Make sure all libraries are in the same folder (with correct rpath etc)
String path = libPath + "/libExtraDependency.so";
System.load(path);
// Note, the actual name is "libmysharedlibrary.so" on linux
Native.register("mysharedlibrary");
} catch (Exception e) {
System.out.println("FATAL: " + e.getMessage());
}
}
}