I am developing an open-source emulator project, and it has multiple, customizable native plug-ins. These plug-ins are built as native shared object libraries (.so files), and have various interfaces between native and Java through JNI. Rather than distribute the APK with every single plug-in ever created, and in order to allow folks to build their own custom plug-ins, I need a method of importing these .so files any time after the app has been installed.
I’ve found that I can copy files to the folder /data/data/[package_name], but not to the lib/ sub-folder (because it is owned by the “system” group). To utilize the JNI interfaces in Java, I must call System.loadLibrary( libname ); However, this seems to require the .so file to be located in the lib/ sub-folder. The only way around this I can think of is to require the user to have a rooted device. Is there another way to accomplish this?
Use System.load() instead:
$ adb logcat
D/LibTest ( 1022): Loading /data/data/com.foo.test/lib/liba.so…
D/dalvikvm( 1022): Trying to load lib /data/data/com.foo.test/lib/liba.so 0x40512640
D/dalvikvm( 1022): Added shared lib /data/data/com.foo.test/lib/liba.so 0x40512640
D/dalvikvm( 1022): No JNI_OnLoad found in /data/data/com.foo.test/lib/liba.so 0x40512640, skipping init
D/LibTest ( 1022): Loading /data/data/com.foo.test/lib/libb.so…
D/dalvikvm( 1022): Trying to load lib /data/data/com.foo.test/lib/libb.so 0x40512640
D/dalvikvm( 1022): Added shared lib /data/data/com.foo.test/lib/libb.so 0x40512640
D/dalvikvm( 1022): No JNI_OnLoad found in /data/data/com.foo.test/lib/libb.so 0x40512640, skipping init