Java and B4A wrapper for a native .so library

divinglog

Member
Licensed User
Longtime User
Hello

I want to use a native C-Library in B4A and as far as I know, the only way to get this working is creating a Java wrapper around the native .so library and then a B4A wrapper for the Java wrapper. So if someone can help me to do this, please contact me.

The native library I want to consume is: https://github.com/libdivecomputer/libdivecomputer

I'm using this lib for several years in my VB.NET project on Windows with pinvoke and I can provide my VB.NET code as a reference. Because special hardware is required for testing, I do NOT expect a ready to use wrapper. A scaffolding with some functions and callbacks should be sufficient for me to complete the project.

Requirements:

- You have to be able to create a Java wrapper for a native .so library
- You have to know how to create a B4A wrapper for the Java wrapper
- You have to know how to call C-code functions from Java and B4A and how to receive callbacks from native code
- It would be helpful if you understand VB.NET code, as I can provide this code as a reference

If there is a better way to consume a native .so library in B4A, please let me know.

You can contact me here in the forum or via Email: info (at) divinglog.de

Thank you,
Sven Knoch
 

DonManfred

Expert
Licensed User
Longtime User
- You have to be able to create a Java wrapper for a native .so library
If you find someone who can compile the .so and create the javawrapper for the native then i can help you creating a b4a wrapper.
If you have contact to the developer. He should be able to create a file like

libdivecomputerJNI.java

with a content like
B4X:
package com.fos.sdk; // Adapt here

import java.util.ArrayList; // Adapt if needed

public class DiveComputerJNI {
    public static native int AddAccount(int i, int i2, String str, String str2, int i3);

    public static native int AddMultiDev(int i, int i2, MultiDevice multiDevice);

    public static native int AddMusicList(int i, int i2, MusicList musicList, CurListInfo curListInfo);

    public static native int AecCloseAudio();

[...]
    static {
        try {
            System.loadLibrary("divecomputer");
        } catch (UnsatisfiedLinkError e) {
            e.printStackTrace();
        }
}
 

divinglog

Member
Licensed User
Longtime User
Thank you DonManfred! Yes, compiling the .so library is something I'll look into. I'm able to compile the Windows DLL, so I think compiling with the Android NDK shouldn't be a problem.
 
Top