在so库中添加打印,android虚拟机不能打印的问题,网上答案太多,一个个试出来的,先记录下来
用的是android-ndk-r8c
遇到的一个问题 用了stdio.h中的printf()添加打印后,在虚拟机中打印不能输出
需要引用库,添加 几个地方才能打开打印
#include <android/log.h>
定义宏
#define LOG_TAG "communicate"
#define LOGI(args...) \
__android_log_print(ANDROID_LOG_INFO,LOG_TAG, args)
#define DEBUG(args...) \
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, args)
#define ERROR(args...) \
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, args)
#else
#define LOGI(args...)
#define DEBUG(args...)
#define ERROR(args...)
#endif
ndk-build编译
发现这个修改之后会出现undefined reference to __android_log_print' 这个问题
然后继续修改Android.mk文件
需要加上几句话
LOCAL_LDLIBS := -lm -llog
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
LOCAL_SHARED_LIBRARIES :=\
liblog.so\
libutils \
搞定