Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output variable contents to "LogCat" window in Android-ndk

I am using Android-sdk-ndk in an Eclipse+ADT environment. In Android-sdk Java development, I could use "Log.i", "Log.w", ... statements to output messages and variable contents to the "LogCat" window. However, in Android-ndk C/C++ development, is there any similar C/C++ "print-like" statement that outputs messages / variable contents from a JNI C/C++ module to the "LogCat" window so that I could have some debug informations for my program.

Thanks for any suggestion.

Lawrence

like image 567
user1129812 Avatar asked Oct 09 '22 00:10

user1129812


1 Answers

From this guide: http://www.srombauts.fr/2011/03/06/standalone-toolchain/

You can #define the logging methods like this:

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "hello-ndk", __VA_ARGS__))

And you need to make sure you're linking to liblog by compiling similar to this (just add -l log):

arm-linux-androideabi-gcc  hello-ndk.c -l log -o hello-ndk
like image 110
Robert Rouhani Avatar answered Oct 17 '22 04:10

Robert Rouhani