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 method name. An object, JNIEnv
, is always passed as a parameter, as well as jobject
—this is required to make the framework interface with Java. The function, written in C, just returns a string...