Debugging an Android NDK application with logging messages
Android logging system provides a method for collecting logs from various applications into a series of circular buffers. The logcat
command is
used to view the logs. Log message is the simplest method of debugging a program, yet one of the most powerful ones. This recipe focuses on message logging in NDK.
How to do it…
The following steps create our sample Android project:
Create an Android application named
NDKLoggingDemo
. Set the package name ascookbook.chapter3
. Create an activity namedNDKLoggingDemoActivity
. 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
NDKLoggingDemo
, select Android Tools | Add Native Support. A window appears, click on Finish to dismiss it.Add a new file named
mylog.h
under thejni
folder, and add the following content to it:#ifndef COOKBOOK_LOG_H #define COOKBOOK_LOG_H...