0

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

No implementation found for native Lc/google/facedetect/FaceDetect;.decodeYUV([I[BII)V

threadid=1:thread exiting with uncaught exception (group=0x40018578)

FATAL EXCEPTION: main java.lang.UnsatisfiedLinkError: decodeYUV

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

The "JNIEXPORT void JNICALL ...." line has a syntax error, maybe that's what causing all the errors ?

My Android.mk file is as follows:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := face-detect

LOCAL_SRC_FILES := face-detect.c

include $(BUILD_SHARED_LIBRARY)

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);
}

Also, Eclipse doesn't say what the syntax error is, it only underlines the JNIExport line and says syntax error

Another UPDATE to answer the question I have indeed checked that the library is being loaded, here is the logcat

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

Community
  • 1
  • 1
Mohamed Heiba
  • 1,813
  • 4
  • 38
  • 67
  • Eclipse doesn't give any more details, it just says syntax error on that line – Mohamed Heiba Jul 16 '12 at 13:00
  • Eclipse is often wrong. It doesn't like C code if it's not pointed at a full set of headers, and with the latest ADT release it is just *randomly* wrong / stale about Java code a lot of the time. See if you can disable the checking, or cut what it is complaining about, save, and clean, then paste it back in. – Chris Stratton Jul 16 '12 at 13:04
  • @ChrisStratton thank you for your comment, so I should ignore this syntax error ? but then why do I keep getting that "no implementation found error" – Mohamed Heiba Jul 16 '12 at 13:06
  • Try running nkd-build from the commandline according to the ndk docs. If that works and generates a library, eclipse is wrong (though it may fail to update you project until you get it to stop checking). But if ndk-build fails, then you may really have an answer. – Chris Stratton Jul 16 '12 at 13:07
  • ndk-build from cygwin bash works perfectly fine and generates the .so file. the java header that has the syntax error is generated by the javah command mentioned in the question. – Mohamed Heiba Jul 16 '12 at 13:15
  • the only reason I'm bothered with this syntax error, is that it may solve the riddle of the "no implementation found" error – Mohamed Heiba Jul 16 '12 at 13:16

1 Answers1

2

There is no syntax error. Check that you are loading your native library and that it has loaded successfuly.

Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
  • thank you for your reply. Writing code in comments is a bit rough, I updated the question, if you can please have a look. Thanks. – Mohamed Heiba Jul 16 '12 at 13:01
  • I have checked that the library is being loaded and updated the question to include the code and the logcat :D – Mohamed Heiba Jul 16 '12 at 13:09
  • Implement JNI_OnLoad and do something observable in it, to be 100% sure that your lib is added correctly. Also dump the symbols exported by your libface-detect.so and post it here. – Pavel Zdenek Jul 16 '12 at 13:56
  • how do I implement JNI_OnLoad ? please advise – Mohamed Heiba Jul 16 '12 at 14:28
  • 1
    [Like this](http://java.sun.com/docs/books/jni/html/other.html#30439). The only mandatory part is returning the minimal supported JNI version. Most probably you would like to [print something into logcat](http://stackoverflow.com/questions/6426911/c-c-printfs-wheres-it-appears-in-a-android-native-code). – Pavel Zdenek Jul 16 '12 at 14:36