I'm Building Taskito
I'm Building Taskito
Get it on Google Play Download on the App Store

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.

Playing around with Android UI

Articles focusing on Android UI - playing around with ViewPagers, CoordinatorLayout, meaningful motions and animations, implementing difficult customized views, etc.

Read next