im trying to implement a native library into my application. But i keep getting errors no matter what i try. So im asking for a little help!
The functions for the lib is stored java-wise in this class:
public class CamLib {
static{
System.loadLibrary("leifdev_com_WaveNet_CamLib");
}
public static native void getSobel(byte[] frame, int width, int height, IntBuffer diff);
}
And is being loaded in like this:
CamLib.getSobel(mFrame, mFrameSize.width, mFrameSize.height, mFrameDiff);
The header file is auto generated by javah and looks like this:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
#include <string.h>
#include <android/log.h>
/* Header for class leifdev_com_WaveNet_CamLib */
#ifndef _Included_leifdev_com_WaveNet_CamLib
#define _Included_leifdev_com_WaveNet_CamLib
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: leifdev_com_WaveNet_CamLib
* Method: getSobel
* Signature: (J)J
*/
JNIEXPORT void JNICALL Java_leifdev_com_WaveNet_CamLib_getSobel
(JNIEnv *, jclass,
jbyteArray , jint , jint , jobject );
#ifdef __cplusplus
}
#endif
#endif
And the function itself is from a tutorial, so i assume its working, and it looks like this:
#include "leifdev_com_WaveNet_CamLib.h"
#define LOGTAG "Sobel_Native"
JNIEXPORT void JNICALL Java_leifdev_com_WaveNet_CamLib_getSobel(
JNIEnv *env, jclass c,
jbyteArray frame, jint width, jint height, jobject diff)
{
jboolean framecopy;
jint *dbuf = (jint*)((*env)->GetDirectBufferAddress(env, diff));
jbyte *fbuf = (*env)->GetByteArrayElements(env, frame, &framecopy);
int x, y, maxx=width-1, maxy=height-1, p=width+1, px, py, ps;
for(y=1; y<maxy; y++, p+=2)
{
for(x=1; x<maxx; x++, p++)
{
px = fbuf[p+width+1]-fbuf[p+width-1]+fbuf[p+1]+fbuf[p+1]-fbuf[p-1]-fbuf[p-1]+fbuf[p-width+1]-fbuf[p-width-1];
py = fbuf[p-width-1]+fbuf[p-width]+fbuf[p-width]+fbuf[p-width+1]-fbuf[p+width-1]-fbuf[p+width]-fbuf[p+width]-fbuf[p+width+1];
if(px<0) px=-px; if(py<0) py=-py;
ps=px+py; if(ps>95) ps=255; if(ps<=95) ps=0;
dbuf[p] = (ps<<24)|(ps<<16)|(ps<<8)|ps;
}
}
}
I am assuming these are the logcat messages of most importance:
08-02 02:07:17.204: D/dalvikvm(15767): No JNI_OnLoad found in /data/data/leifdev.com/lib/libleifdev_com_WaveNet_CamLib.so 0x41a02998, skipping init
08-02 02:07:17.204: W/dalvikvm(15767): No implementation found for native Lleifdev/com/CamLib;.getSobel ([BIILjava/nio/IntBuffer;)V
08-02 02:07:17.204: D/AndroidRuntime(15767): Shutting down VM
08-02 02:07:17.204: W/dalvikvm(15767): threadid=1: thread exiting with uncaught exception (group=0x40c631f8)
08-02 02:07:17.219: V/Camera-JNI(15767): dataCallback(16, 0x7f5778)
08-02 02:07:17.224: V/Camera-JNI(15767): copyAndPost: off=0, size=1036800
08-02 02:07:17.224: V/Camera-JNI(15767): Allocating callback buffer
08-02 02:07:17.334: E/AndroidRuntime(15767): FATAL EXCEPTION: main
08-02 02:07:17.334: E/AndroidRuntime(15767): java.lang.UnsatisfiedLinkError: getSobel
08-02 02:07:17.334: E/AndroidRuntime(15767): at leifdev.com.CamLib.getSobel(Native Method)
(Sorry for spelling errors, its getting really late.)
I have been stuck at this stage for a couple of days now, i think it has something to do with using jclass instead of jobject in the native header, but i cant really find any documentation on it. So if any of you black wizards of ndk could help me out, i would be really happy!
LogCat says your class CamLib should be in leifdev.com
package, but your JNI function expects it to be in leifdev.com.WaveNet
So rename your JNI function to Java_leifdev_com_CamLib_getSobel