Debugging an Android NDK application with CheckJNI
JNI does little error checking for better performance.
As a result, errors usually lead to a crash. A mode called CheckJNI
is offered by Android. In this mode, a set of JNI functions with extended checks are called instead of the normal JNI functions. This recipe discusses how to enable the CheckJNI mode to debug Android NDK applications.
How to do it...
The following steps create a sample Android project and enable the CheckJNI
mode:
Create an Android application named
CheckJNIDemo
. Set the package name ascookbook.chapter3
. Create an activity namedCheckJNIDemoActivity
. Please refer to the Loading native libraries and registering native methods recipe of Chapter 2, Java Native Interface, if you want more detailed instructions.Right-click on the project
CheckJNIDemo
, select Android Tools | Add Native Support. A window appears; click on Finish to dismiss it.Add the following content to
CheckJNIDemo.cpp
.Change
CheckJNIDemoActivity.java
to the...