简体   繁体   English

为 Android NDK 使用 Google Breakpad?

[英]Using Google Breakpad for Android NDK?

Is anyone using Google Breakpad for Android native code (NDK) ?有人使用Google Breakpad for Android native code (NDK) 吗?

If so, could you elaborate on how to get it up and running (the client side that is).如果是这样,您能否详细说明如何启动和运行它(即客户端)。 The docs are very limited and don't mention Android at all.文档非常有限,根本没有提到 Android。 The build system contains android information though which make me think it shouldn't be a problem.构建系统包含 android 信息,尽管这让我认为这应该不是问题。

Sorry about that, I did the initial port but I didn't really document anything. 对不起,我做了初始端口,但我没有真正记录任何内容。 However, one of the Chrome engineers did some work on the port and wrote a really nice README: https://chromium.googlesource.com/breakpad/breakpad/+/master/README.ANDROID 然而,其中一位Chrome工程师在端口上做了一些工作,写了一篇非常好的自述文件: https//chromium.googlesource.com/breakpad/breakpad/+/master/README.ANDROID

There's also an NDK-compatible Android.mk file in there now, so if you're using the standard NDK build system it should be simple to incorporate Breakpad. 现在还有一个与NDK兼容的Android.mk文件,所以如果你使用的是标准的NDK构建系统,那么加入Breakpad应该很简单。

I also found a good example project for that. 我也找到了一个很好的示例项目 As it is in the project you can set up Google Breakpad like: 就像在项目中一样,您可以设置Google Breakpad,如:

extern "C" {
    void Java_com_pluusystem_breakpadjavacall_MainActivity_initNative(JNIEnv* env, jobject obj, jstring filepath)
    {
        const char *path = env->GetStringUTFChars(filepath, 0);
        google_breakpad::MinidumpDescriptor descriptor(path);
        exceptionHandler = new google_breakpad::ExceptionHandler(descriptor, NULL, DumpCallback, NULL, true, -1);
    }
}

in the cpp side and like: 在cpp方面,像:

    // Save Dump Path
    initNative(getExternalCacheDir().getAbsolutePath());

in the java side. 在java方面。

After that implementing the bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) function you will be able to do something before the app crashes. 在实现bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded)功能之后,您将能够在应用程序崩溃之前执行某些操作。

I have experienced and also found this issue which confirms me, that in this function you can't do java callbacks under ART just under DVM (before android 5 - Lollipop). 我有经验,也发现这个问题证实了我,在这个函数中,你不能在ART下在AVM下(在android 5 - Lollipop之前)做java回调。

My example repo for Flutter Android/iOS: https://github.com/Sunbreak/flutter-breakpad.trial我的 Flutter Android/iOS 示例存储库: https : //github.com/Sunbreak/flutter-breakpad.trial


Android安卓

$NDK is local path of your Android NDK directory $NDK 是你的 Android NDK 目录的本地路径

$CLI_BREAKPAD is local clone of https://github.com/Sunbreak/cli-breakpad.trial $CLI_BREAKPAD 是https://github.com/Sunbreak/cli-breakpad.trial 的本地克隆

cd $BREAKPAD/src/android
cp -r google_breakpad jni
$NDK/ndk-build
  • Install libbreakpad_client.a of all architectures安装所有架构的libbreakpad_client.a
mkdir -p ./android/app/src/main/cmakeLibs
cp -r $BREAKPAD/src/android/obj/local/* ./android/app/src/main/cmakeLibs/
  • run on macOS/Linux在 macOS/Linux 上运行
# Device/emulator connected
$ android_abi=`adb shell getprop ro.product.cpu.abi`
$ flutter run
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
I/flutter_breakpad(31631): JNI_OnLoad
D/flutter_breakpad(31631): Dump path: /data/data/com.example.flutter_breakpad/files/f5258c0e-eff3-433a-7ea47880-c756fc17.dmp
$ adb shell "run-as com.example.flutter_breakpad sh -c 'cat /data/data/com.example.flutter_breakpad/files/f5258c0e-eff3-433a-7ea47880-c756fc17.dmp'" >| libflutter-breakpad.so.dmp
$ $CLI_BREAKPAD/breakpad/linux/$(arch)/dump_syms build/app/intermediates/cmake/debug/obj/${android_abi}/libflutter-breakpad.so > libflutter-breakpad.so.sym
$ uuid=`awk 'FNR==1{print \$4}' libflutter-breakpad.so.sym`
$ mkdir -p symbols/libflutter-breakpad.so/$uuid/
$ mv ./libflutter-breakpad.so.sym symbols/libflutter-breakpad.so/$uuid/
$ $CLI_BREAKPAD/breakpad/linux/$(arch)/minidump_stackwalk libflutter-breakpad.so.dmp symbols/ > libflutter-breakpad.so.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM