Game Development Reference
In-Depth Information
The Java Interface Pointer
Native code in C/C++ accesses the Java Virtual Machine through JNI functions that are accessed
through the Java Interface Pointer. The JNI Interface Pointer is a pointer to an array of pointers that
point to JNI functions. (See Figure 11-3 .)
JNI Interface Pointer
(JNIEnv* env)
Array of pointers
to JNF Functions
An Interface Function
NewStringUTF()
Pointer
Pointer
Pointer
GetObjectClass()
Pointer
...
GetMethodID()
Figure 11-3. The Java Interface Pointer
Loading and Linking Native C/C++ Methods
In order to use native classes in your Android Java code (see Listing 11-1), you will have to
Load the compiled library by using the System.loadLibrary() function.
1.
2.
Declare the native class that is defined in the C/C++ source code as native in
the Android Java code by using the native keyword in a function declaration.
Listing 11-1. Loading and Linking Native C/C++ Methods from Android Java Code
package robs.gldemo.robsgl20tutorial;
class GLES20TriangleRenderer implements GLSurfaceView.Renderer
{
/* this is used to load the 'hello-jni' library on application
* startup. The library has already been unpacked into
* /data/data/com.example.hellojni/lib/libhello-jni.so at
* installation time by the package manager.
*/
static {
System.loadLibrary("hello-jni");
}
public native String RobsstringFromJNI();
}
 
Search WWH ::




Custom Search