JNI

JNI stands for Java Native Interface. JNI allows libraries and software written in other languages to access the Java code that is running in the Java Virtual Machine (JVM). This is not something Android-related, but a programming framework that has existed and been used previously in the Java world.

JNI needs files to be declared into either C or C++—it can even connect to Objective-C files. This is what an example in C looks like:

jstring
Java_com_my_package_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
    return (*env)->NewStringUTF(env, "Hello World");
}

Observing the file, we can see that after the return type, jstring, which is equivalent to a string, there is structure with the word Java, the package name, the class name, and the ...

Get Android High Performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.