Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ printfs - Where's it appears in a Android native code?

Tags:

Since It's pretty hard to debug native android code, I'm going to the "printf trace" approach.

So, my question is, in a native code, wheres the standards "printf("something")" appears when running a Android application?

like image 981
Marcos Vasconcelos Avatar asked Jun 21 '11 14:06

Marcos Vasconcelos


People also ask

What is native code in Android?

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 C library does Android use?

Bionic is an implementation of the standard C library, developed by Google for its Android operating system.


1 Answers

Log to logcat.

1) To invoke the logger in native code include the header and call _android_log_write(..).

#include <android/log.h>  __android_log_write(ANDROID_LOG_INFO, "tag here", "message here"); 

2) In your Android.mk file include the log lib like this.

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog  
like image 154
Ryan Reeves Avatar answered Nov 09 '22 10:11

Ryan Reeves