Game Development Reference
In-Depth Information
Android JNI Makefile
The Android makefile ( Android.mk ) is a file that describes your native code that you want to compile
to the NDK build system.
The LOCAL_PATH variable holds the location of the source files. The value of my-dir is already defined
by the NDK build system to point to the current directory that contains the Android.mk makefile.
What you will do is put this makefile in the JNI directory, along with all the C source code files that
you want to compile.
LOCAL_PATH := $(call my-dir)
The CLEAR_VARS variable is already defined by the NDK build system and points to a makefile that will
clear many of the local variables that are used in the build system.
include $(CLEAR_VARS)
The LOCAL_MODULE variable sets the library name that will be generated from the native source code
files. The library name format will be the prefix “ lib ” + “ hello-jni ” + the “ .so ” suffix. However, if the
library name already begins with “ lib ”, the prefix “ lib ” is not added to the final file name.
LOCAL_MODULE := hello-jni
The LOCAL_SRC_FILES variable holds the names of the C/C++ source files that the NDK build system
will compile and create a final library from.
LOCAL_SRC_FILES := hello-jni.c
The BUILD_SHARED_LIBRARY variable is defined by the NDK build system and points to a makefile that
gathers and processes all the information needed for building the final library.
include $(BUILD_SHARED_LIBRARY)
The complete makefile is shown in Listing 11-6.
Listing 11-6. The Android JNI Makefile
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
Hands-on Example: “Hello World from JNI and Native Code”
In this hands-on example, a simple “Hello World” example is discussed, in which the actual string
“Hello World from JNI and Native Code” is generated from native C code and returned to the Java
caller where it is then printed out to the log window.
 
Search WWH ::




Custom Search