How to determine return type for JNI method with user class Object?

I have a method in JNI (C ++) and I want to be able to return a custom object type (not primitive or String, etc.) I wrote something, but I keep getting java.lang.UnsatisfiedLinkError.

Here are the details:

Method:

static jobject Java_android_sdk_Core_ProcessFrame(JNIEnv *env, jobject myobj, jbyteArray frameData)
    {

     jclass clazz;
     jmethodID cid;
     jobject jCoreOut;
     static const char* const strClassName = "android/sdk/Core/CoreOutput";
     clazz = env->FindClass(strClassName);
     if (clazz == NULL) {
      LOGE("Can't find class CoreOutput");

     }
     cid = env->GetMethodID(clazz,"<init>", "()V");
     jCoreOut = env->NewObject(clazz, cid);


     // Free local references 
        env->DeleteLocalRef(clazz);

     return jCoreOut;

    }

I have method descriptors defined as follows:

    static const JNINativeMethod gMethods[] = {
        { "CreateCore", "(III)V", (void*) Java_android_sdk_Core_CreateCore },
  { "ProcessFrame", "([B)Landroid/sdk/Core/CoreOutput;", (void*) Java_android_sdk_Core_ProcessFrame }
 };

I am registering a method by calling:

     if (env->RegisterNatives(clazz, gMethods,
    sizeof(gMethods) / sizeof(gMethods[0])) != JNI_OK)
 {
  LOGE("Failed registering JNI methods");
  return result;
 }

And registering my other own methods is successful. (I can use them ...)

When I try to call the ProcessFrame method, I get the following output from Logcat:

11-23 16:10:10.139: ERROR/AndroidRuntime(4923): java.lang.UnsatisfiedLinkError: ProcessFrame

I am sure this is relevant to me without defining the method correctly. Can anyone shed some light on this?

Can someone point me to a good tutorial that covers more than handling primitive types in JNI?

Thank,

Itamar

+3
1

UnsatisfiedLinkError , JVM . , . javah . : javah

+1

Source: https://habr.com/ru/post/1776524/


All Articles