#include "client/crashpad_client.h"
#include "client/crash_report_database.h"
#include "client/settings.h"
using namespace crashpad;
extern "C" JNIEXPORT jboolean JNICALL
Java_com_example_androidcrasher_MainActivity_initializeCrashpad(
string dataDir = "/data/data/com.example.androidcrasher";
FilePath handler(dataDir + "/lib/libcrashpad_handler.so");
FilePath reportsDir(dataDir + "/crashpad");
FilePath metricsDir(dataDir + "/crashpad");
// Crashpad upload URL for BugSplat database
string url = "http://{{database}}.bugsplat.com/post/bp/crash/crashpad.php";
map<string, string> annotations;
annotations["format"] = "minidump"; // Required: Crashpad setting to save crash as a minidump
annotations["database"] = "{{database}}"; // Required: BugSplat database
annotations["product"] = "{{appName}}"; // Required: BugSplat appName
annotations["version"] = "{{appVersion}}"; // Required: BugSplat appVersion
annotations["key"] = "Key"; // Optional: BugSplat key field
annotations["list_annotations"] = "Sample comment"; // Optional: BugSplat crash description
vector<string> arguments;
arguments.push_back("--no-rate-limit");
// Crashpad local database
unique_ptr<CrashReportDatabase> crashReportDatabase = CrashReportDatabase::Initialize(reportsDir);
if (crashReportDatabase == NULL) return false;
// Enable automated crash uploads
Settings *settings = crashReportDatabase->GetSettings();
if (settings == NULL) return false;
settings->SetUploadsEnabled(true);
// File paths of attachments to be uploaded with the minidump file at crash time - default bundle limit is 20MB
vector<FilePath> attachments;
FilePath attachment(dataDir + "/files/attachment.txt");
attachments.push_back(attachment);
// Start Crashpad crash handler
static CrashpadClient *client = new CrashpadClient();
bool status = client->StartHandlerAtCrash(handler, reportsDir, metricsDir, url, annotations, arguments, attachments);