19

Is anyone using 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. The build system contains android information though which make me think it shouldn't be a problem.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
olafure
  • 3,518
  • 2
  • 33
  • 45
  • Can it work on Android though since it does not support C++ exception handling? I would love it if it works!!! – Cipi Jul 13 '12 at 16:37
  • It does support C++ Exception handling as well – Kevin Parker Jul 17 '12 at 15:49
  • I can build the client by copying the android/google_breakpad/Android.mk into the root of the google breakpad source, editing to remove the ../.. from the .mk file and putting it all in my NDK_MODULES directory, but can't build the host tools to actually make sense of the mini dump, at least not using cygwin. – Tom Whittock Jul 19 '12 at 20:39
  • Most of the Breakpad tools aren't very cross-compile friendly. You'll need to build dump_syms on a Linux system (maybe Cygwin would work, I've never tried). minidump_stackwalk should build fine on any POSIX setup including Cygwin. – Ted Mielczarek Apr 11 '13 at 11:52

4 Answers4

9

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

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.

olafure
  • 3,518
  • 2
  • 33
  • 45
Ted Mielczarek
  • 3,919
  • 26
  • 32
  • Anybody able to use breakpad with the newest NDK which requires c++_shared/static library instead of STLport or GNU libstdc++? – pembeci Apr 15 '19 at 10:26
1

I also found a good example project for that. As it is in the project you can set up Google Breakpad like:

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:

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

in the java side.

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.

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).

bendaf
  • 2,981
  • 5
  • 27
  • 62
0

My example repo for Flutter Android/iOS: https://github.com/Sunbreak/flutter-breakpad.trial


Android

$NDK is local path of your Android NDK directory

$CLI_BREAKPAD is local clone of 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
mkdir -p ./android/app/src/main/cmakeLibs
cp -r $BREAKPAD/src/android/obj/local/* ./android/app/src/main/cmakeLibs/
  • run on 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
Sunbreak
  • 391
  • 3
  • 8
0

In a nutshell, on a Linux host, you can cross compile the Breakpad source using an Andriod NDK and the "autoconf" method documented here:

https://developer.android.com/ndk/guides/other_build_systems#autoconf

The Breakpad Android docs fail to mention all the environmental variables you need to set!

BuvinJ
  • 10,221
  • 5
  • 83
  • 96