Question

I am trying to invoke a native callback method from an IntentService written in java. The code snippet in IntentService is like this -

private static native void native_notificationCallback();
public void somemethod(){
    //some other code... 
    native_notificationCallback();
}

Another one is in a separate class -

private static native void native_initCallback();
public void somemethod(){
    //some other code... 
    native_initCallback();
}

The inteface.cpp is like this -

void JNICALL Notification_initCallback(JNIEnv* env, jobject obj)
{
    //code
}

void JNICALL Notification_notificationCallback(JNIEnv* env, jobject obj)
{
    //code
}

void init(){
    static const JNINativeMethod methods[] =
    {
        {"native_initCallback","()V",(void*)&Notification_initCallback},
        {"native_notificationCallback","()V",(void*)&Notification_notificationCallback}
    };

    // Register the native hooks
    if (env->RegisterNatives(cls, methods,sizeof(methods)/sizeof(methods[0])))
        goto fail;
}

The problem is when I call native_initCallback it works perfect, but when I call native_notificationCallback the app crashes giving java.lang.UnsatisfiedLinkError. I don't understand why it worked for the first method and why not for second, since both of them are almost identical except the name.

Was it helpful?

Solution

You say that the two native methods are in different classes, but in your RegisterNatives call you assign them both to one class. If you want to register each method with a different class you'll have to make two RegisterNatives calls. The method is keyed by the class, the name and the signature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top