1.修改Android.mk文件

在mk中所有的LOCAL_SHARED_LIBRARIES地方添加

LOCAL_SHARED_LIBRARIES:=\

libcutils\

libutils

2.在c中添加:

#include <stdint.h>
#include <cutils/debugger.h>
#include <fcntl.h>
#include <errno.h>
#define NE_FOLDER_PATH "/storage/sdcard1/data"
#define NE_FILE_NAME "ne_dump"
#define NE_DUMP (NE_FOLDER_PATH NE_FILE_NAME)

//code部分


char filename[100];
sprintf(filename,"%s.txt",NE_DUMP);
int fd = open(filename,O_CREAT | O_WRONLY,0777);
if(fd < 0){
    fprintf(stderr,"can not open %s,%s\n",filename,strerror(errno));
}
if(lseek(fd,0,SEEK_END)<0){
    fprintf(stderr,"can not open %s\n",strerror(errno));
} else {
    dump_backtrace_to_file(getpid(),fd);
}
close(fd);


3.在build,push重启后,添加权限

adb shell mkdir /storage/sdcard1/data
adb shell chmod 777 /storage/sdcard1/data

这样就能打出backtrace到文件/storage/sdcard1/data/ne_dump.txt了

 

在java中打印backtrace:

在指定的函数内打印相关java调用

法1:RuntimeException r = new RuntimeException("srx");
   r.printStackTrace();
法2:Exception e = new Exception();
   e.printStackTrace();
法3:

Log.e(TAG,Log.getStackTraceString(new Throwable()));

posted on 2014-05-26 17:41  snowdrop  阅读(663)  评论(0编辑  收藏  举报