Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any simple way to log in Android NDK code?

I'm looking for a way to easily debug C code in an Android NDK application using Eclipse. I've read ways to debug the app using gdb or something similar but what I want is a way to push messages to Eclipse somehow.

I'm looking for a solution that's as simple as using a print function in C and seeing it in the DDMS Log or anything similar. Does anyone have any experience doing this?

like image 703
wajiw Avatar asked Jan 07 '11 19:01

wajiw


People also ask

What can I do with Android NDK?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.

What compiler does Android NDK use?

The NDK itself invokes a customized cross-compiler built on the arm-eabi-gcc compiler.


1 Answers

You can use the Android logging facilities:

#include <android/log.h>  #define APPNAME "MyApp"  __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "The value of 1 + 1 is %d", 1+1); 

Make sure you also link against the logging library, in your Android.mk file:

  LOCAL_LDLIBS := -llog 
like image 192
svdree Avatar answered Oct 21 '22 20:10

svdree