Follow on native libraries
Hello all,
As some others on this forum, I’m very keen to use native shared libraries with B4A. In my case, because I’ve loads of scientific functions written in plain C, that have been optimized for speed. Java is nice but just too slow when it comes to serious number crunching: I made a few tests to interface native functions with Java in Eclipse, and found it to be a good compromise before I discovered B4A, which is a treat for people like me, ie not too Java-driven or “object-oriented”. Though it can do much,much more, it seems the perfect solution to provide quick UI to interface with number crunching software, and I rushed the library tutorial, which showed how simple it was to glue B4A with the java world. Kudos to Erel…:sign0098:
My troubles began when trying to write a Java wrapper that could load a toy shared library written in C (libmylib.so) that has a single function that returns a “Hello world” string through JNI interface. When compiled under Eclipse, loaded with a System.LoadLibrary,(“mylib”) from a test Activity, all is well. At install time, the Eclipse made apk create a /data/data/<package name>/lib folder in which the libmylib.so is placed. At run time, the naltive libray is loaded correctly and the test string is returned fine. As I read a post reply from Erel saying that a working Android .so could probably be wrapped in a library, I had to try....
So I designed a B4A library , with basically the same declaration/loading/calling sequence, but I didn’t know how to tell B4A to install automatically the libmylib.so file. B4A creates a /data/data/<B4A package name>/lib folder, but it is empty
So, I added the .so file to the assets folder, and tried to File.Copy it to a sdcard location, while replacing System.LoadLibrary with System.Load () with the chosen path (before Diming my library class instance). B4A logs now finds the .so file, but crashes with a “java.lang.UnsatisfiedLinkError: Cannot load library: load_segments failed to map segment from “ error. It seems it’s a known error when attempting to override default lib folders.
I tried to File.Copy it to /data/data/<B4A package name>/lib folder, but File.copy returned a permission denied error. Before going further, and try to push the file through adb, could anybody please tell me if there is something basically wrong with my approach? I’m a noob in Android & Java, and I ‘m pretty sure I’m not doing this the correct way..
So, has anybody actually managed to interface native code with B4A?:sign0163:
Moreover, If interfacing native file with B4A is possible, could someone please give some links/detais (or a simple example of how to do it ?
If not, I would very much have it in the wish list?
Thanks a lot in advance