0

谷歌 breakpad 捕捉到信号(关于通过 JNI 在本机代码中崩溃),但应用程序仍然在它之后死机。应该怎么做才能预防呢?

日志:

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.

代码:

#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");
}
4

1 回答 1

0

在某些情况下,即使您使用BreakpadCoffeeCatch ,也无法防止您的应用程序崩溃。

但是,您将在崩溃发生之前收到通知。您可以利用这段时间警告用户正在发生的事情(致命错误)和接下来会发生的事情(应用程序将强制关闭)。

于 2014-03-08T13:19:17.260 回答