1

I'm trying to create a phonegap plugin for an android device, sadly my Java is terrible.

I have a simple helloworld project i'm working in to try and get this going. I've created a plugin which loads fine and works ( just a simple return string example )

From this i then have tried to add my native library code.

public class Medida extends CordovaPlugin
{

static {
    System.loadLibrary("finger");
}

public native static int SFM_Init(byte[] dev);

The error message i keep encountering is: 10-28 15:23:03.207: W/dalvikvm(11618): No implementation found for native Lorg/apache/cordova/plugin/Medida;.SFM_Init ([B)I

Now - I'm taking the libfinger.so file from a full JAVA android project and trying to wrap it into a phonegap plugin (why? Because i can code phonegap, but no java).

The files are all been placed in the correct locations the libfinger.so file is in the libs/ folder

So my question is - what else do i need to add-in or do to get the JAVA plugin to work with the libfinger.so - so i can call all the clases etc..

Thanks for looking - spents days trying to find out, but there is not much info on calling loadlibrary for plugins which i understand.

John

Main java class
package org.apache.cordova.plugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;


public class Medida extends CordovaPlugin{

static {
    System.loadLibrary("finger");
}

public native static int SFM_Init(byte[] dev);


static final String LOG_TAG = "Medida.Java: ";
int fd = 0;
String retval = null;
int[] nQuality = {0};
int[] nBufferSize = {0};
private final String retSuccess = "OK";
public static final int REFRESH = 1;
public static final int ERROR = 0;
private Thread thread = null;
private int peripheral_fd = 1;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("dave")) {
        String message = args.getString(0);
        this.dave("Medida CALLING DAVE " + message, callbackContext);
        return true;
    }
    else if (action.equals("scanfinger_getID")){
         this.scanfinger_getID( args, callbackContext);
         return true;
    }

    return false;
}

private void dave(String message, CallbackContext callbackContext) {
    if (message != null && message.length() > 0) {
        callbackContext.success(" --- Medida FROM DAVE: " + message);
    } else {
        callbackContext.error("Expected one non-empty string argument.");
    }
}

private void scanfinger_getID(JSONArray args, CallbackContext callbackContext) throws JSONException {
    String message = args.getString(0);
    JSONObject object = new JSONObject(message);
    String id = object.getString("id");


    String dev = "/dev/ttySAC3";
    byte[] devName = dev.getBytes();
    fd = SFM_Init(devName);


    callbackContext.success("Got to scanfinger_getID: " + id);

}

}

Dawson Loudon
  • 6,029
  • 2
  • 27
  • 31

1 Answers1

2

Try to define the method as a class method (taken from here):

public class Medida extends CordovaPlugin {

  static {
      System.loadLibrary("finger");
  }

  public native int SFM_Init(byte[] dev);
}

EDIT

From the error it seems that there is no method called SFM_Init in the native library, try to list the exported methods and see the exact definition: How do I list the symbols in a .so file

Community
  • 1
  • 1
Miquel
  • 8,339
  • 11
  • 59
  • 82
  • Thankyou for this - it pointed me in the correct direction - as a result i have managed to at least call processes through the library file. I thought i could just use the library file and call the process ( My java is terrible ) but after some heavy reading, i have included a load more files from another native project which uses this library file - I know have some hope of moving forward. – user3468134 Nov 03 '14 at 15:05