Breakpad 在Android上的集成,官方的文档相对简单,也是unix类系统标准的方式。
使用NDK编译breakpad
首先,需要安装ndk,从理论上说,Windows、Linux、mac的ndk都可以,并把ndk-build命令加入path中。
把目录breakpad/android/google_breakpad改名为jni,再在breakpad/android/下运行ndk-build命令。
遇到错误"third_party/lss/linux_syscall_support.h"。解决方法:在/breakpad/src/third_party下建立lss目录,然后从https://chromium.googlesource.com/linux-syscall-support/+/refs/heads/main下载linux_syscall_support.h的压缩包,然后把linux_syscall_support.h文件放入到/breakpad/src/third_party/lss目录中,再次编译。
breakpad/android/obj/local下会出现各个架构的libbreakpad_client.a文件。
如果需要动态库或者只需要部分架构的,就自己去找一下Android.mk的写法。
在android C中的调用方式
#include "client/linux/handler/exception_handler.h"
static google_breakpad::ExceptionHandler* g_ExceptionHandler = nullptr;
static bool OnMinidumpGenerated(const google_breakpad::MinidumpDescriptor& descriptor,
void* context,
bool succeeded) {
printf("Dump path: %s\n", descriptor.path());
return succeeded;
}
google_breakpad::MinidumpDescriptor descriptor(path);
g_ExceptionHandler = new google_breakpad::ExceptionHandler(descriptor,
NULL,
OnMinidumpGenerated,
NULL,
true,
-1);
tips:
- 为了保证ExceptionHandler的有效性,不要把ExceptionHandler生成的指针放到局部作用域中。
- path应当传入一个可写的路径,比如 /Downloads路径。
- OnMinidumpGenerated 作为一个回调函数,也是需要保证他在整个程序的生命周期中都有效的。
头文件
单纯的这样include 会发现少了很多文件,如果有耐心的话,可以根据提示,一个一个找回,如果没耐心的话,就直接把breakpad整个文件夹拷贝到项目对应的目录下。
饮用
https://chromium.googlesource.com/breakpad/breakpad/+/master/docs/linux_starter_guide.md