onmyway133
onmyway133

Reputation: 48185

JNI functions in Android webkit source

I read that JNI functions (the native C part) is very complex and must contain the java package name.

However, when reading Android webkit source. For example the nativeMoveGeneration functions in WebView.java

private native int      nativeMoveGeneration();

It calls the JNI functions in WebView.cpp

static int nativeMoveGeneration(JNIEnv *env, jobject obj)
{
    WebView* view = GET_NATIVE_VIEW(env, obj);
    if (!view)
        return 0;
    return view->moveGeneration();
}

Ihis JNI function does not follow naming rule. Why is it?

P/S: The function above is just for demonstration. I'm reading Android 4.0.3 source, so it may be different from the github source above

UPDATE Thanks to @Alex Cohn and this JNI Tips, I know that we can use JNI_Onload or use complex name. But where should we put JNI_Onload ?

Upvotes: 2

Views: 916

Answers (1)

Alex Cohn
Alex Cohn

Reputation: 57203

JNI defines special function, JNI_OnLoad. It is called before any JNI method is called, and it can populate the table of native methods using pointers to any C functions. See the official document

Upvotes: 1

Related Questions