Java Question Problem with JNI...

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody,
I'm facing this issue trying to reuse an old JNI library.
I have written a Java wrapper to create a B4A library, when I execute it I get:

B4X:
running waiting messages (1)
** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
java.lang.UnsatisfiedLinkError: open
    at org_sipdroid_codecs.GSM.open(Native Method)
    at org_sipdroid_codecs.GSM.openx(GSM.java:31)
    at b4a.example.main._activity_create(main.java:325)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at b4a.example.main.afterFirstLayout(main.java:98)
    at b4a.example.main.access$100(main.java:16)
    at b4a.example.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
The code for wrapper is
B4X:
package org_sipdroid_codecs;

//import java.io.IOException;

//import android.util.Log;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
//import anywheresoftware.b4a.objects.streams.File;

@Version(1.0f)
@ShortName("GSM")





public class GSM  {
       
    private native int open();
    private native int decode(byte encoded[], short lin[], int size);
    private native int encode(short lin[], int offset, byte encoded[], int size);
    private native void close();
    static {
          System.loadLibrary("gsm_jni");
   
      }

    public int openx()
    {
   
        return open();       
    }
    public int decodex(byte encoded[], short lin[], int size)
    {
    return decode( encoded,  lin, size);       
    }
   
    public  int encodex(short lin[], int offset, byte encoded[], int size)
   
    {
        return encode(lin,  offset,  encoded, size);       
        }
       
    public void closex()
    {
    close();       
    }

    }


The code for B4A is:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim buff(320) As Short
    Dim buffa(320) As Short
    Dim buffo(33) As Byte
    Dim leng As Int
    Dim offset As Int
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
  Dim n As Int
  For n= 1 To 319
    buff(n)=(n Mod 10)
  Next   
  Dim GSM As GSM
  GSM.openx()
  GSM.encodex(buff,offset, buffo,leng)
  GSM.decodex(buffo,buff,leng)
  GSM.closex
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

while the Java interface for JNI open function is:

B4X:
extern "C"
JNIEXPORT jint JNICALL Java_org_sipdroid_codecs_GSM_open
  (JNIEnv *env, jobject obj) {
    int ret;

From the stack i can see that instead of calling Java_org_sipdroid_codecs_GSM_open
it calls org_sipdroid_codecs.GSM.open
I don't understand very well the dynamics of this automatic name generation. Can anybody help me?

Nice day
Mauro
 

warwound

Expert
Licensed User
Longtime User
B4X:
package org_sipdroid_codecs;

Is a valid package name but it's not the same as:

B4X:
package org.sipdroid.codecs;

Martin.
 

tigrot

Well-Known Member
Licensed User
Longtime User
After learning more than 100 languages(Assemblies and compilers) I start to make big confusion...
Let's give a try, changing package name underscores to dots! Thank you for hint: I didn't notice this... And Java is last of the list... Last time I used it was to make fixes on OpenGts more than two years ago.
 
Top