Java Question JNI

Johan Schoeman

Expert
Licensed User
Longtime User
I am trying to wrap a SKD for a B4A member. The folder structure looks as follows:

src
main
java
com
uniview
smb
ezsdk
demo
6_different_files.java​
wrapper
DeviceWrapper.java​
jni
netdevsdk
include
NetDEVSDK.h​
lib
7 x .so files​
Android.mk​
Android.mk
Application.mk
ezsdk.cpp​
res
some res folders and files
In the MainActivity.java of the demo project the 7 .so files are loaded

B4X:
    static {
        System.loadLibrary("Curl");
        System.loadLibrary("MP4");
        System.loadLibrary("mXML");
        System.loadLibrary("NDPlayer");
        System.loadLibrary("NDRender");
        System.loadLibrary("NetDEVSDK");
        System.loadLibrary("RM_Module");
        System.loadLibrary("ezsdk3.0");
    }

There are 7 .so files available but System.loadLibrary("ezsdk3.0"); is an 8th system library that needs to be loaded. My guess is that this library somehow needs to be generated from the NetDEVSDK.h file.

The wrapper (DeviceWrapper.java) is probably the wrapper for this interface. It looks as follows:

B4X:
package com.uniview.smb.ezsdk.wrapper;

import android.util.Log;
import android.view.Surface;

import com.uniview.smb.ezsdk.demo.ChannelInfo;
import com.uniview.smb.ezsdk.demo.DeviceInfo;

import java.util.ArrayList;

public class DeviceWrapper {
    private static String TAG = "WRAP";
    public native int sdkInit();
    public native int sdkLogin(String deviceIP, int port, String userName, String userPass);
    public native int sdkLogout(int userID);
    public native int sdkGetVersion();
    public native int sdkGetLastError();
    public native ArrayList<ChannelInfo> sdkGetChlList(int userID);
    public native int sdkStartLive(int userID, int channel);
    public native int sdkStopLive(int handle);
    public native int sdkCapture(int handle, String fileName);
    public static native void setRenderSurface(Surface view);

    public static boolean sdkInited = false;
    public DeviceWrapper() {
        if (DeviceWrapper.sdkInited)
            return;

        DeviceWrapper.sdkInited = true;
        sdkInit();

        Log.i(TAG, "SDK initialized, version " + sdkGetVersion());
    }

    public int GetLastError()
    {
        return sdkGetLastError();
    }

    public int Login(DeviceInfo deviceInfo)
    {
        return sdkLogin(deviceInfo.deviceIP, deviceInfo.devicePort, deviceInfo.userName, deviceInfo.userPass);
    }

    public int Logout(int userID)
    {
        return sdkLogout(userID);
    }

    public ArrayList<ChannelInfo> GetChlList(int userID)
    {
        return sdkGetChlList(userID);
    }

    public int StartLive(int userID, int channel) {
        return sdkStartLive(userID, channel);
    }

    public int StopLive(int handle) {
        return sdkStopLive(handle);
    }

    public int CapturePic(int handle, String fileName) {
        return sdkCapture(handle, fileName);
    }
}

NetDEVSDK.h is attached to this post


So how do I create ezsdk3.0 from all this other JNI stuff? My own wrapper merely kickstarts MainActivity.java into action as I need to see what this looks like and what it does.

Should all the .mk files and .h files somehow be used to generate ezsdk3.0.xxx (an .so file?)

Help with this will be much appreciated - have never done anything like this.
 

Attachments

  • NetDEVSDK.zip
    32.6 KB · Views: 287

JordiCP

Expert
Licensed User
Longtime User
My guess is that if libezsdk3.0.so isn't included in any folder, it should be generated with the NDK and there ought to be enough info of how to do it in android.mk in jni folder
 

JordiCP

Expert
Licensed User
Longtime User
I have seen the directory structure now. It seems to be that the files are there. So I think the steps are:

Run a command shell in the JNI folder, and call "ndk-build" (you must have the ndk previously installed and being part of your path) .
If everything goes ok, it will place the generated .so files in "Libs" folder (at least this is what happened with the version I had).
Then you need to copy those files from "libs" folder to "lib" folder
 

Johan Schoeman

Expert
Licensed User
Longtime User
My guess is that if libezsdk3.0.so isn't included in any folder, it should be generated with the NDK and there ought to be enough info of how to do it in android.mk in jni folder
So, I guess this should be done via Eclipse?
 

JordiCP

Expert
Licensed User
Longtime User
I think there are 2 ways

> Build the .so files independently with the ndk-build (as described before) and place them in the "lib" folder (this is what I do with the few libs that I have written). ndk-build uses the android.mk
> Configure eclipse to do also this part when you build the whole project. I suppose it is easy, but I never succeeded with it :eek:
 

Johan Schoeman

Expert
Licensed User
Longtime User
I think there are 2 ways

> Build the .so files independently with the ndk-build (as described before) and place them in the "lib" folder (this is what I do with the few libs that I have written). ndk-build uses the android.mk
> Configure eclipse to do also this part when you build the whole project. I suppose it is easy, but I never succeeded with it :eek:
I will give it a go. What do you mean with "part of your path"
""....you must have the ndk previously installed and being part of your path...."
 

JordiCP

Expert
Licensed User
Longtime User
From the JNI folder, you can call

> C:\Android\android-ndk-r9\ndk-build (assuming this is where you have your ndk)
or
> ndk-build (if the previous route is added to your PATH environment variable)
 

Johan Schoeman

Expert
Licensed User
Longtime User
You only need to make sure that the library structure is correct. See this post: https://www.b4x.com/android/forum/threads/loading-so-library-files-error.54414/#post-341528
Hi Erel - I have the folder structure correctly in my project and the .so files in the right place (have done this before with some other projects). But this library...
System.loadLibrary("ezsdk3.0");

..is not available as a .so file and seems to me as if it somehow needs to be created with the NDK (from the .h files and the .mk files). I have downloaded the NDK last night and tried it as what @JordiCP suggested but have not had any success thus far. A little bit lost with exactly how to do this...
 

moster67

Expert
Licensed User
Longtime User
..is not available as a .so file and seems to me as if it somehow needs to be created with the NDK (from the .h files and the .mk files). I have downloaded the NDK last night and tried it as what @JordiCP suggested but have not had any success thus far. A little bit lost with exactly how to do this...
If you like, you can PM me a link from where I can download the project (or the github-link) and I can try to compile it for you this weekend. I've done this already a few times in the past...
 

Johan Schoeman

Expert
Licensed User
Longtime User
If you like, you can PM me a link from where I can download the project (or the github-link) and I can try to compile it for you this weekend. I've done this already a few times in the past...
Thanks @moster67. Will send you a link later today when back home from work

Rgds

JS
 

Johan Schoeman

Expert
Licensed User
Longtime User
If you like, you can PM me a link from where I can download the project (or the github-link) and I can try to compile it for you this weekend. I've done this already a few times in the past...
Thanks Mike (@moster67). You are a machine! It is working.
 
Top