Game Development Reference
In-Depth Information
jni_send_str (string, 0);
}
va_list , va_start , and va_end are used to build an output string using a C string format and a
sequence of arguments. This allows the developer to mimic a printf -style function for a specific need.
Thus, for example, to print an arbitrary message to the Java console within the library, use the following
command:
jni_printf("This is a message %d, %p, %x, %s", 10, somePointer, 0xFF, "Hello Java")
"This is a message %d, %p, %x, %s" is called a character format. The rest are variable arguments
sent to the function. Also note that you should add the header #include <stdarg.h> to use variable
arguments.
Compiling and Testing the Shared Library
We can now proceed to compile the native library. Listing 2-6 shows the Makefile for this purpose. This
file defines the following targets:
default ( all ): This target will build both the library and the test static binary
a.out .
lib : This target will build only the shared library.
testlib : This target will build a simple program to test the library and make sure
there are no missing symbols.
jni : This target will generate the C header for the native Java class jni.Natives .
The output will be stored in the include folder under the current directory.
pushbin : This target will push the static test binary ( a.out ) to the device /data
folder using the adb push command.
pushlib : This target will push the library and the test program to the device /data
folder.
Caution Commands within a target of a Makefile must use the tab separator, which has been replaced by
spaces in Listing 2-6. Do not copy and paste this listing into a Makefile, as it will not run properly. Instead, refer to
the source code for the chapter.
Listing 2-6. Makefile for This Chapter's Example
#####################################
# Makefile
#####################################
Search WWH ::




Custom Search