Skip to content
Open
Show file tree
Hide file tree
Changes from 15 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
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ elseif(SENTRY_BACKEND_NATIVE)
backends/native/sentry_crash_ipc.c
backends/native/sentry_crash_daemon.c
backends/native/sentry_crash_handler.c
backends/native/sentry_crash_unwind.h
backends/native/minidump/sentry_minidump_format.h
backends/native/minidump/sentry_minidump_writer.h
)
if(SENTRY_WITH_LIBUNWINDSTACK)
sentry_target_sources_cwd(sentry
backends/native/sentry_crash_unwind_libunwindstack.cpp
)
endif()

# Platform-specific minidump writers
if(LINUX OR ANDROID)
Expand All @@ -194,7 +200,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
Loading
Loading