Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d7983aa
feat(native): Add Android support
jpnurmi May 15, 2026
92d076e
fix(native): Avoid leaking Android daemon IPC fds
jpnurmi May 15, 2026
25beed6
Update CHANGELOG.md
jpnurmi May 15, 2026
bdb7cbf
Fix skipifs
jpnurmi May 15, 2026
b984030
fix(native): Remove stale Android daemon parameter casts
jpnurmi May 15, 2026
0930ddb
default is_android to 0 instead of None
jpnurmi May 15, 2026
2c9a5d9
fix(native): Require Android IPC database path
jpnurmi May 15, 2026
c499043
test: Handle empty Android API in conditions
jpnurmi May 15, 2026
9c5c7df
skip mac sandbox tests on android
jpnurmi May 15, 2026
03a811f
WIP
jpnurmi May 19, 2026
11f94c3
curl
jpnurmi May 19, 2026
a410bf0
clean up
jpnurmi May 19, 2026
3e9a856
Merge remote-tracking branch 'upstream/master' into jpnurmi/feat/nati…
jpnurmi May 19, 2026
f823609
fix warnings
jpnurmi May 19, 2026
9ffa097
fix(android): Unwind native daemon crashes with libunwindstack
jpnurmi May 19, 2026
bbe8817
fix(android): Preserve previous native signal handlers
jpnurmi May 19, 2026
1251b9a
fix(android): Queue native crashes for tombstone merging
jpnurmi May 19, 2026
71655dc
fix(android): Use native crash reporting without minidumps
jpnurmi May 19, 2026
1ecaa52
feat(android): Add native backend preload support
jpnurmi May 20, 2026
f6b5caf
fix(android): Respect tombstone setting in NDK crash mode
jpnurmi May 20, 2026
0d6923e
test(android): Clean native test database after crash
jpnurmi May 20, 2026
57004b7
feat(transport): Add stdout transport
jpnurmi May 20, 2026
6460208
WIP: tombstone merge support
jpnurmi May 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

**Features**:

- Native: add Android support. ([#1725](https://github.com/getsentry/sentry-native/pull/1725))

**Fixes**:

- Reject overly deep msgpack payloads during deserialization. ([#1727](https://github.com/getsentry/sentry-native/pull/1727))
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,11 @@ elseif(SENTRY_BACKEND_NATIVE)
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/src/backends/native
)
if(SENTRY_WITH_LIBUNWINDSTACK)
target_include_directories(sentry-crash PRIVATE
${PROJECT_SOURCE_DIR}/external/libunwindstack-ndk/include
)
endif()

# Link same libraries as sentry
target_link_libraries(sentry-crash PRIVATE ${_SENTRY_PLATFORM_LIBS})
Expand Down
3 changes: 3 additions & 0 deletions ndk/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ systemProp.org.gradle.internal.http.socketTimeout=120000
android.nonTransitiveRClass=true

android.suppressUnsupportedCompileSdk=34

# TODO: clean up
sentryBackend=native
Comment thread
cursor[bot] marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POC debug configuration committed in gradle properties

Medium Severity

The sentryBackend=native property in gradle.properties with a # TODO: clean up comment overrides the default "inproc" backend for all NDK library builds. This POC-only configuration changes the default behavior for every consumer of the NDK module. Similarly, the unconditional implementation("io.github.vvb2060.ndk:curl:8.18.0") dependency (with its own # TODO) bloats the AAR for non-native-backend builds. Both TODO comments indicate these are temporary and not meant to be permanent.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3e9a856. Configure here.

20 changes: 20 additions & 0 deletions ndk/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,29 @@ endif()
set(BUILD_SHARED_LIBS ON)
set(SENTRY_BUILD_SHARED_LIBS ON)

if(SENTRY_BACKEND STREQUAL "native")
find_package(curl REQUIRED CONFIG)
if(NOT TARGET CURL::libcurl)
add_library(CURL::libcurl INTERFACE IMPORTED)
target_link_libraries(CURL::libcurl INTERFACE curl::curl_static)
endif()
set(SENTRY_TRANSPORT "curl" CACHE STRING "" FORCE)
endif()

# Adding sentry-native project
add_subdirectory(${SENTRY_NATIVE_SRC} sentry_build)

if(SENTRY_BACKEND STREQUAL "native")
target_compile_definitions(sentry-android PRIVATE SENTRY_BACKEND_NATIVE)
set_target_properties(sentry-crash PROPERTIES
PREFIX "lib"
OUTPUT_NAME "sentry-crash"
SUFFIX ".so"
)
target_link_options(sentry-crash PRIVATE "-Wl,-z,max-page-size=16384")
target_link_libraries(sentry-android PRIVATE dl)
endif()

# Android logging library
find_library(LOG_LIB log)

Expand Down
12 changes: 10 additions & 2 deletions ndk/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
}

var sentryNativeSrc: String = "${project.projectDir}/../.."
val sentryBackend = providers.gradleProperty("sentryBackend").orElse("inproc").get()

android {
compileSdk = 35
Expand All @@ -18,6 +19,7 @@ android {
externalNativeBuild {
cmake {
arguments.add(0, "-DANDROID_STL=c++_static")
arguments.add(0, "-DSENTRY_BACKEND=$sentryBackend")
arguments.add(0, "-DSENTRY_NATIVE_SRC=$sentryNativeSrc")
}
}
Expand Down Expand Up @@ -51,6 +53,7 @@ android {
}

buildFeatures {
prefab = true
prefabPublishing = true
buildConfig = true
}
Expand Down Expand Up @@ -100,6 +103,9 @@ android {
}

dependencies {
// TODO: this was the first match on maven central..
implementation("io.github.vvb2060.ndk:curl:8.18.0")

compileOnly("org.jetbrains:annotations:23.0.0")

testImplementation("androidx.test.ext:junit:1.3.0")
Expand Down Expand Up @@ -137,10 +143,12 @@ dependencies {
*
*/
afterEvaluate {
tasks.getByName("prefabReleasePackage") {
tasks.matching { it.name.startsWith("prefab") && it.name.endsWith("Package") }.configureEach {
doLast {
project.fileTree("build/intermediates/prefab_package/") {
project.fileTree("build/intermediates/") {
include("**/abi.json")
include("**/prefab_publication.json/debug")
include("**/prefab_publication.json/release")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Malformed glob patterns will never match files

Medium Severity

The include patterns **/prefab_publication.json/debug and **/prefab_publication.json/release treat prefab_publication.json as a directory containing files named debug/release. Since prefab_publication.json is a regular file (not a directory), these Ant-style glob patterns will never match anything. The c++_staticnone replacement intended for those files silently won't happen, which can cause STL-related linking issues for AAR consumers. The patterns likely need to be **/prefab_publication/debug/** and **/prefab_publication/release/**, or simply **/prefab_publication.json.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 03a811f. Configure here.

}.forEach { file ->
file.writeText(file.readText().replace("c++_static", "none"))
}
Expand Down
38 changes: 38 additions & 0 deletions ndk/lib/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
#include <sentry.h>
#include <jni.h>

#if defined(SENTRY_BACKEND_NATIVE)
#include <dlfcn.h>
#include <limits.h>

#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
#endif

#define ENSURE(Expr) \
if (!(Expr)) \
return
Expand Down Expand Up @@ -59,6 +68,31 @@ static char *call_get_string(JNIEnv *env, jobject obj, jmethodID mid) {
return NULL;
}

#if defined(SENTRY_BACKEND_NATIVE)
static void set_handler_path(sentry_options_t *options) {
Dl_info info;
if (dladdr((void *)set_handler_path, &info) == 0 || !info.dli_fname) {
return;
}

const char *slash = strrchr(info.dli_fname, '/');
if (!slash) {
return;
}

const char daemon_name[] = "libsentry-crash.so";
size_t dir_len = (size_t)(slash - info.dli_fname + 1);
if (dir_len + sizeof(daemon_name) > PATH_MAX) {
return;
}

char handler_path[PATH_MAX];
memcpy(handler_path, info.dli_fname, dir_len);
memcpy(handler_path + dir_len, daemon_name, sizeof(daemon_name));
sentry_options_set_handler_path(options, handler_path);
}
#endif

JNIEXPORT void JNICALL
Java_io_sentry_ndk_NativeScope_nativeSetTag(
JNIEnv *env,
Expand Down Expand Up @@ -350,6 +384,10 @@ Java_io_sentry_ndk_SentryNdk_initSentryNative(
options = sentry_options_new();
ENSURE_OR_FAIL(options);

#if defined(SENTRY_BACKEND_NATIVE)
set_handler_path(options);
#endif

// session tracking is enabled by default, but the Android SDK already handles it
sentry_options_set_auto_session_tracking(options, 0);

Expand Down
6 changes: 3 additions & 3 deletions ndk/sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ set(SENTRY_BUILD_SHARED_LIBS ON)

add_library(ndk-sample SHARED src/main/cpp/ndk-sample.cpp)

# Adding sentry-native project
add_subdirectory(${SENTRY_NATIVE_SRC} sentry_build)
# Use sentry-native from the NDK library's Prefab package
find_package(sentry-native-ndk REQUIRED CONFIG)

# Android logging library
find_library(LOG_LIB log)

target_link_libraries(ndk-sample PRIVATE
${LOG_LIB}
$<BUILD_INTERFACE:sentry::sentry>
sentry-native-ndk::sentry
)
# Support 16KB page sizes
target_link_options(ndk-sample PRIVATE "-Wl,-z,max-page-size=16384")
8 changes: 4 additions & 4 deletions ndk/sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ plugins {
kotlin("android")
}

var sentryNativeSrc: String = "${project.projectDir}/../.."

android {
compileSdk = 35
namespace = "io.sentry.ndk.sample"
buildFeatures.buildConfig = true
buildFeatures {
buildConfig = true
prefab = true
}

defaultConfig {
applicationId = "io.sentry.ndk.sample"
Expand All @@ -20,7 +21,6 @@ android {
externalNativeBuild {
cmake {
arguments.add(0, "-DANDROID_STL=c++_shared")
arguments.add(0, "-DSENTRY_NATIVE_SRC=$sentryNativeSrc")
}
}

Expand Down
2 changes: 2 additions & 0 deletions ndk/sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application tools:ignore="MissingApplicationIcon">

<activity
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ elseif(SENTRY_BACKEND_NATIVE)
target_include_directories(sentry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/backends/native)

# Platform-specific libraries for native backend
if(LINUX OR ANDROID)
if(LINUX AND NOT ANDROID)
# Linux needs pthread and rt for shared memory
target_link_libraries(sentry PRIVATE pthread rt)
elseif(APPLE)
Expand Down
9 changes: 4 additions & 5 deletions src/backends/native/minidump/sentry_minidump_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# include "sentry_minidump_format.h"
# include "sentry_minidump_indirect.h"
# include "sentry_minidump_writer.h"
# include "sentry_os.h"

// NT_PRSTATUS is defined in linux/elf.h but we can't include that
// because it conflicts with elf.h. Define it here if not available.
Expand Down Expand Up @@ -66,9 +67,6 @@ struct fpsimd_context {
# endif
# endif

// Use process_vm_readv to read memory from crashed process
# include <sys/uio.h>

// Use shared constants from crash context
# include "../sentry_crash_context.h"

Expand Down Expand Up @@ -346,7 +344,8 @@ read_process_memory(
struct iovec local_iov = { .iov_base = buf, .iov_len = len };
struct iovec remote_iov = { .iov_base = (void *)addr, .iov_len = len };

ssize_t nread = process_vm_readv(tid, &local_iov, 1, &remote_iov, 1, 0);
ssize_t nread
= sentry__process_vm_readv(tid, &local_iov, 1, &remote_iov, 1, 0);
if (nread > 0) {
return nread;
}
Expand Down Expand Up @@ -2135,7 +2134,7 @@ linux_indirect_read_memory(void *ctx, uint64_t addr, void *buf, size_t len)
pid_t tid = writer->crash_ctx->crashed_tid;
struct iovec local_iov = { .iov_base = buf, .iov_len = len };
struct iovec remote_iov = { .iov_base = (void *)addr, .iov_len = len };
return process_vm_readv(tid, &local_iov, 1, &remote_iov, 1, 0);
return sentry__process_vm_readv(tid, &local_iov, 1, &remote_iov, 1, 0);
}

/**
Expand Down
53 changes: 43 additions & 10 deletions src/backends/native/sentry_crash_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "sentry_json.h"
#include "sentry_logger.h"
#include "sentry_options.h"
#include "sentry_os.h"
#include "sentry_path.h"
#include "sentry_process.h"
#include "sentry_screenshot.h"
Expand Down Expand Up @@ -351,6 +352,7 @@ build_registers_from_ctx(const sentry_crash_context_t *ctx, size_t thread_idx)
&& thread_idx < ctx->platform.num_threads) {
uctx = &ctx->platform.threads[thread_idx].context;
}
(void)uctx;

# if defined(__x86_64__)
uintptr_t *mctx = (uintptr_t *)&uctx->uc_mcontext;
Expand Down Expand Up @@ -801,8 +803,8 @@ build_stacktrace_for_thread(
= { .iov_base = stack_buf, .iov_len = stack_size };
struct iovec remote_iov
= { .iov_base = (void *)stack_start, .iov_len = stack_size };
ssize_t bytes_read
= process_vm_readv(pid, &local_iov, 1, &remote_iov, 1, 0);
ssize_t bytes_read = sentry__process_vm_readv(
pid, &local_iov, 1, &remote_iov, 1, 0);
if (bytes_read <= 0) {
SENTRY_DEBUG(
"process_vm_readv failed, falling back to single frame");
Expand Down Expand Up @@ -3237,7 +3239,11 @@ daemon_file_logger(
fflush(log_file); // Flush immediately to ensure logs are written
}

#if defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID)
#if defined(SENTRY_PLATFORM_ANDROID)
int
sentry__crash_daemon_main(pid_t app_pid, uint64_t app_tid, int notify_eventfd,
int ready_eventfd, int shm_fd)
#elif defined(SENTRY_PLATFORM_LINUX)
int
sentry__crash_daemon_main(
pid_t app_pid, uint64_t app_tid, int notify_eventfd, int ready_eventfd)
Expand All @@ -3253,7 +3259,10 @@ sentry__crash_daemon_main(pid_t app_pid, uint64_t app_tid, HANDLE event_handle,
{
// Initialize IPC first (attach to shared memory created by parent)
// We need this to get the database path for logging
#if defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID)
#if defined(SENTRY_PLATFORM_ANDROID)
sentry_crash_ipc_t *ipc = sentry__crash_ipc_init_daemon(
app_pid, app_tid, notify_eventfd, ready_eventfd, shm_fd);
#elif defined(SENTRY_PLATFORM_LINUX)
sentry_crash_ipc_t *ipc = sentry__crash_ipc_init_daemon(
app_pid, app_tid, notify_eventfd, ready_eventfd);
#elif defined(SENTRY_PLATFORM_MACOS)
Expand Down Expand Up @@ -3532,7 +3541,11 @@ sentry__crash_daemon_main(pid_t app_pid, uint64_t app_tid, HANDLE event_handle,
return 0;
}

#if defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID)
#if defined(SENTRY_PLATFORM_ANDROID)
pid_t
sentry__crash_daemon_start(pid_t app_pid, uint64_t app_tid, int notify_eventfd,
int ready_eventfd, int shm_fd, const char *handler_path)
#elif defined(SENTRY_PLATFORM_LINUX)
pid_t
sentry__crash_daemon_start(pid_t app_pid, uint64_t app_tid, int notify_eventfd,
int ready_eventfd, const char *handler_path)
Expand Down Expand Up @@ -3653,6 +3666,12 @@ sentry__crash_daemon_start(pid_t app_pid, uint64_t app_tid, HANDLE event_handle,
if (ready_flags != -1) {
fcntl(ready_eventfd, F_SETFD, ready_flags & ~FD_CLOEXEC);
}
# if defined(SENTRY_PLATFORM_ANDROID)
int shm_flags = fcntl(shm_fd, F_GETFD);
if (shm_flags != -1) {
fcntl(shm_fd, F_SETFD, shm_flags & ~FD_CLOEXEC);
}
# endif

// Convert arguments to strings for exec
char pid_str[32], tid_str[32], notify_str[32], ready_str[32];
Expand All @@ -3661,8 +3680,15 @@ sentry__crash_daemon_start(pid_t app_pid, uint64_t app_tid, HANDLE event_handle,
snprintf(notify_str, sizeof(notify_str), "%d", notify_eventfd);
snprintf(ready_str, sizeof(ready_str), "%d", ready_eventfd);

# if defined(SENTRY_PLATFORM_ANDROID)
char shm_str[32];
snprintf(shm_str, sizeof(shm_str), "%d", shm_fd);
char *argv[] = { "sentry-crash", pid_str, tid_str, notify_str,
ready_str, shm_str, NULL };
# else
char *argv[]
= { "sentry-crash", pid_str, tid_str, notify_str, ready_str, NULL };
# endif
Comment thread
cursor[bot] marked this conversation as resolved.

if (!sentry__string_empty(handler_path)) {
execv(handler_path, argv);
Expand Down Expand Up @@ -3830,12 +3856,13 @@ main(int argc, char **argv)
{
// Expected arguments:
// Linux: <app_pid> <app_tid> <notify_handle> <ready_handle>
// macOS: <app_pid> <app_tid> <notify_handle> <ready_handle> <shm_fd>
# if defined(SENTRY_PLATFORM_MACOS)
// macOS/Android: <app_pid> <app_tid> <notify_handle> <ready_handle>
// <shm_fd>
# if defined(SENTRY_PLATFORM_MACOS) || defined(SENTRY_PLATFORM_ANDROID)
if (argc < 6) {
fprintf(stderr,
"Usage: sentry-crash <app_pid> <app_tid> <notify_pipe> "
"<ready_pipe> <shm_fd>\n");
"Usage: sentry-crash <app_pid> <app_tid> <notify_handle> "
"<ready_handle> <shm_fd>\n");
return 1;
}
# else
Expand All @@ -3851,7 +3878,13 @@ main(int argc, char **argv)
pid_t app_pid = (pid_t)strtoul(argv[1], NULL, 10);
uint64_t app_tid = strtoull(argv[2], NULL, 16);

# if defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID)
# if defined(SENTRY_PLATFORM_ANDROID)
int notify_eventfd = atoi(argv[3]);
int ready_eventfd = atoi(argv[4]);
int shm_fd_arg = atoi(argv[5]);
return sentry__crash_daemon_main(
app_pid, app_tid, notify_eventfd, ready_eventfd, shm_fd_arg);
# elif defined(SENTRY_PLATFORM_LINUX)
int notify_eventfd = atoi(argv[3]);
int ready_eventfd = atoi(argv[4]);
return sentry__crash_daemon_main(
Expand Down
Loading
Loading