Adding Logs in JNI Code | Jay Rambhia’s Blog

Adding Logs in JNI Code

I am working with NDK and Android so sometimes I need to debug the native code to see if it’s working properly or not. I wanted something similar to Android’s Log function.

So here’s how to use log in Native code.

#include <android/log.h>

#define APPNAME "module_name jni"
#define LOGD(TAG) __android_log_print(ANDROID_LOG_DEBUG , APPNAME,TAG);

To use this in some function, just use it as following.

    LOGD("some content here");

To check value of some variable

    int rows = 512;

    char rowStr[10];
    char rStr[] = "Rows = ";

    sprintf(rowStr, "%d", rows);
    strcat(rowStr, rStr);
    LOGD(rowStr); // prints Rows = 512

P.S. Write OpenCV C++ and use it with NDK. Things are so good.