1
即時嘗試將本機庫實現到我的應用程序。但是,無論我嘗試什麼,我都會收到錯誤。所以即時通訊尋求一點幫助!Android Ndk(沒有發現爲xxxxx實現)
用於LIB的功能被存儲Java的明智在這個類:
public class CamLib {
static{
System.loadLibrary("leifdev_com_WaveNet_CamLib");
}
public static native void getSobel(byte[] frame, int width, int height, IntBuffer diff);
}
而被加載在這樣的:
CamLib.getSobel(mFrame, mFrameSize.width, mFrameSize.height, mFrameDiff);
由JAVAH和外觀產生的頭文件自動像這樣:
/* 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
而該函數本身來自一個教程,所以我假設它的工作,它看起來就像這樣:
#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;
}
}
}
我假定這是最重要的logcat的信息:(對不起拼寫錯誤,它變得非常晚)
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)
我一直停留在這個階段現在有好幾天了,我認爲這與在本地頭文件中使用jclass而不是jobject有關,但我無法真正找到任何文檔。 因此,如果你們中的任何一個黑巫師能幫助我,我會非常高興!
這工作!謝謝,這讓我的一天變得完美了! – user1419305 2012-08-02 13:20:30