的Android NDK,我用下面的命令来生成JNI头,
Android NDK, I used the following command to generate the jni header,
C:\eclipse_workspace\C_Google_FaceDetect\bin>javah -jni -verbose -classpath C:\Android_SDK\platforms\android-10;C:\eclipse_workspace\C_Google_FaceDetect\src;. -d C:\eclipse_workspace\C_Google_FaceDetect\jni c.google.facedetect.FaceDetect
问题是即使我把一切都很好,我得到了以下错误
The problem is even though I set everything well, I'm getting the following error
没有发现本地LC /谷歌/ facedetect / FaceDetect执行;由Matchi.com提供回到codeYUV([I [BII)V
No implementation found for native Lc/google/facedetect/FaceDetect;.decodeYUV([I[BII)V
主题ID = 1:螺纹未捕获的异常(组= 0x40018578)退出
threadid=1:thread exiting with uncaught exception (group=0x40018578)
致命异常:主要java.lang.UnsatisfiedLinkError中:德codeYUV
FATAL EXCEPTION: main java.lang.UnsatisfiedLinkError: decodeYUV
我试图寻找什么是错的,我发现,在c_google_facedetect_FaceDetect.h JNI头文件,我有一个语法错误,其实(即使它生成的)
I tried looking for what's wrong, and I found that in the c_google_facedetect_FaceDetect.h jni header file, I have a syntax error actually (even though it's generated)
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h> /* Header for class c_google_facedetect_FaceDetect */
#ifndef _Included_c_google_facedetect_FaceDetect
#define _Included_c_google_facedetect_FaceDetect
#ifdef __cplusplus extern "C" {
#endif
#undef c_google_facedetect_FaceDetect_CAMERA_WIDTH
#define c_google_facedetect_FaceDetect_CAMERA_WIDTH 480L
#undef c_google_facedetect_FaceDetect_CAMERA_HEIGHT
#define c_google_facedetect_FaceDetect_CAMERA_HEIGHT 320L
/*
* Class: c_google_facedetect_FaceDetect
* Method: decodeYUV
* Signature: ([I[BII)V
*/
JNIEXPORT void JNICALL Java_c_google_facedetect_FaceDetect_decodeYUV(JNIEnv *, jobject, jintArray, jbyteArray, jint, jint);
#ifdef __cplusplus }
#endif
#endif
在JNIEXPORT无效JNICALL ....行有语法错误,或许这就是造成所有的错误?
The "JNIEXPORT void JNICALL ...." line has a syntax error, maybe that's what causing all the errors ?
我的Android.mk文件如下:
My Android.mk file is as follows:
LOCAL_PATH:= $(叫我-DIR)
LOCAL_PATH := $(call my-dir)
中包括$(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE:=脸检测
LOCAL_MODULE := face-detect
LOCAL_SRC_FILES:=面detect.c
LOCAL_SRC_FILES := face-detect.c
中包括$(BUILD_SHARED_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
更新我的唯一的java文件称为FaceDetect.java并包含有以下code
UPDATE My one and only java file is called FaceDetect.java and includes the following code
public class FaceDetect extends Activity implements SurfaceHolder.Callback, Camera.PreviewCallback
{
static
{
Log.d("mytag", "before_lib");
System.loadLibrary("face-detect");
Log.d("mytag", "after_lib");
}
public static native void decodeYUV(int[] out, byte[] fg, int width, int height);
}
此外,Eclipse不说语法错误是什么,它只是强调了JNIEXPORT线,并说语法错误
Also, Eclipse doesn't say what the syntax error is, it only underlines the JNIExport line and says syntax error
另一个更新来回答这个问题我确实已检查该库被加载,这里是logcat的
Another UPDATE to answer the question I have indeed checked that the library is being loaded, here is the logcat
13 07-16:31:43.257:D / MyTag的(25188):before_lib 07-16 13:31:43.281:D / dalvikvm(25188):试图加载的lib /data/data/c.google.facedetect/lib/libface-detect.so 0x40517808 07-16 13:31:43.281:D / dalvikvm(25188):增加了共享库/data/data/c.google.facedetect/lib/libface-detect.so 0x40517808 07-16 13:31:43.281:D / dalvikvm(25188):无JNI_OnLoad在/data/data/c.google.facedetect/lib/libface-detect.so 0x40517808发现,跳过初始化07-16 13:31:43.281:D / MyTag的(25188):after_lib
07-16 13:31:43.257: D/mytag(25188): before_lib 07-16 13:31:43.281: D/dalvikvm(25188): Trying to load lib /data/data/c.google.facedetect/lib/libface-detect.so 0x40517808 07-16 13:31:43.281: D/dalvikvm(25188): Added shared lib /data/data/c.google.facedetect/lib/libface-detect.so 0x40517808 07-16 13:31:43.281: D/dalvikvm(25188): No JNI_OnLoad found in /data/data/c.google.facedetect/lib/libface-detect.so 0x40517808, skipping init 07-16 13:31:43.281: D/mytag(25188): after_lib
有没有语法错误。检查是否加载的本地库,它已successfuly加载。
There is no syntax error. Check that you are loading your native library and that it has loaded successfuly.