Google breakpad catches signal (about crash in native code via JNI) but the app still dies after it. What should be done in order to prevent it?
log:
03-08 15:04:13.398: ERROR/NATIVE_LIB(2828): init breakpad
03-08 15:04:13.398: ERROR/NATIVE_LIB(2828): testing crash
03-08 15:04:13.468: ERROR/NATIVE_LIB(2828): Dump path: ./5f6097b2-5feb-0723-3271a7ff-2a4fcadd.dmp
03-08 15:04:13.468: WARN/crash_handler(2828): Caught a crash, signum=11
...
03-08 15:04:14.589: INFO/ActivityManager(544): Process name.antonsmirnov.android.app (pid 2828) has died.
code:
#include "native_lib.h"
#include <stdio.h>
#include "client/linux/handler/exception_handler.h"
#include "client/linux/handler/minidump_descriptor.h"
#include <android/log.h>
void debug(const char *format, ... ) {
va_list argptr;
va_start(argptr, format);
__android_log_vprint(ANDROID_LOG_ERROR, "NATIVE_LIB", format, argptr);
va_end(argptr);
}
bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
void* context,
bool succeeded) {
debug("Dump path: %s\n", descriptor.path());
return succeeded;
}
JNIEXPORT jint JNICALL Java_name_antonsmirnov_android_app_libnative_func(JNIEnv *env, jobject obj)
{
debug("init breakpad");
google_breakpad::MinidumpDescriptor descriptor(".");
google_breakpad::ExceptionHandler eh(descriptor, NULL, DumpCallback, NULL, true, -1);
{
debug("testing crash\n");
char *ptr = 0;
*ptr = '!'; // ERROR HERE!
debug("unreachable\n");
}
debug("finished\n");
}
In some cases, there is no way of preventing your app from crashing, even if you use Breakpad or CoffeeCatch.
However, you will be notified before the crash occurs. You can use that time to warn the user about what is happening (a fatal error) and what will happen next (the app will force close).