Fork me on GitHub

Adding Logs in JNI Code

Posted on 15 March 2014
Under Notes
Tagged
Android
Adding Logs in JNI Code | Jay Rambhia’s Blog

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.

If you liked - Adding Logs in JNI Code and found it helpful, please share it with your fellow developers.

comments powered by Disqus


If you have some feedback or questions regarding this post, please add comments. I'd be happy to get some feedback.



If you liked this post, then you should follow Jay on twitter too. He would be excited to know that you like his work.