What is the Log API to call from an Android JNI program?

hopia picture hopia · Mar 29, 2011 · Viewed 33.3k times · Source

I would like to debug a JNI C application by inserting log messages to logcat. What is the C API that does this?

Answer

Ryan Reeves picture Ryan Reeves · Mar 29, 2011

Like this:

#include <android/log.h>


__android_log_write(ANDROID_LOG_ERROR, "Tag", "Error here");//Or ANDROID_LOG_INFO, ...  

Add it to your makefile like this:

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog