C / C ++ printfs - Where does it appear in Android source code?

Since it’s quite difficult to debug native Android code, I’m moving on to the "printf trace" approach.

So my question is, what do the "printf (" something ") standards appear in the native code when the Android application starts?

+21
android debugging android-ndk
Jun 21 2018-11-11T00:
source share
2 answers

Log in to logcat.

1) To call the logger in your own code, include the header and call _android_log_write (..).

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

2) Your Android.mk file contains a log file similar to this.

 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog 
+41
Jun 21 '11 at 16:21
source share

Shorter macros are available to log in.

 #define LOG_TAG "my_log_tag" #include <cutils/log.h> ALOGD("Format this %d", some_int); 

In Android.mk, add the liblog library to LOCAL_SHARED_LIBRARIES when building in 'mydroid' (a complete build of the Android system). In case of assembly LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -Llog you can use LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -Llog .

 include $(CLEAR_VARS) LOCAL_MODULE := foo LOCAL_SRC_FILES := foo.c # if mydroid LOCAL_SHARED_LIBRARIES := liblog # in ndk, use LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog instead include $(BUILD_EXECUTABLE) 

There are various other macros defined for all levels of logging. From cutils/log.h :

 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) ... #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) 
+1
Mar 31 '15 at 1:01
source share



All Articles