Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 337
hopia Avatar asked Mar 28 '11 22:03

hopia


People also ask

How does JNI work on Android?

It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++). JNI is vendor-neutral, has support for loading code from dynamic shared libraries, and while cumbersome at times is reasonably efficient.

What is NDK and JNI?

JNI is just the way that Java handles calling into native/C++ code, and calling back into Java from there. It has nothing to say about Android - it is a Java language feature. The Android NDK is a way to write Android applications using code called by JNI.


1 Answers

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  
like image 142
Ryan Reeves Avatar answered Oct 19 '22 04:10

Ryan Reeves