diff --git a/CHANGELOG.md b/CHANGELOG.md index 506807466..fc79c6a80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ **Breaking changes**: - If you use a narrow string path interface (for instance, `sentry_options_set_database_path()`) on _Windows_ rather than one of the wide string variants (`sentry_options_set_database_pathw()`), then the expected encoding is now UTF-8. ([#1413](https://github.com/getsentry/sentry-native/pull/1413)) +- Android NDK: `SentryNdk.init(NdkOptions)` now returns an `int` (0 success, non-zero failure) instead of `void`, exposing the result of `sentry_init()`. ([#1430](https://github.com/getsentry/sentry-native/pull/1430)) **Fixes**: diff --git a/ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java b/ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java index d43ac268a..5c7c914eb 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java @@ -10,7 +10,10 @@ public final class SentryNdk { private SentryNdk() {} - private static native void initSentryNative(@NotNull final NdkOptions options); + /** + * Initializes sentry-native and returns 0 on success, non-zero on failure. + */ + private static native int initSentryNative(@NotNull final NdkOptions options); private static native void shutdown(); @@ -19,9 +22,9 @@ private SentryNdk() {} * * @param options the SentryAndroidOptions */ - public static void init(@NotNull final NdkOptions options) { + public static int init(@NotNull final NdkOptions options) { loadNativeLibraries(); - initSentryNative(options); + return initSentryNative(options); } /** Closes the NDK integration */ diff --git a/ndk/lib/src/main/jni/sentry.c b/ndk/lib/src/main/jni/sentry.c index 827ec5bab..6be3765c3 100644 --- a/ndk/lib/src/main/jni/sentry.c +++ b/ndk/lib/src/main/jni/sentry.c @@ -247,7 +247,7 @@ static void send_envelope(sentry_envelope_t *envelope, void *data) { sentry_envelope_free(envelope); } -JNIEXPORT void JNICALL +JNIEXPORT jint JNICALL Java_io_sentry_ndk_SentryNdk_initSentryNative( JNIEnv *env, jclass cls, @@ -355,8 +355,8 @@ Java_io_sentry_ndk_SentryNdk_initSentryNative( jfloat traces_sample_rate = (jfloat) (*env)->CallFloatMethod(env, sentry_ndk_options, traces_sample_rate_mid); sentry_options_set_traces_sample_rate(options, traces_sample_rate); - sentry_init(options); - return; + int rv = sentry_init(options); + return (jint) rv; fail: if (!transport_owns_path) { @@ -366,6 +366,7 @@ Java_io_sentry_ndk_SentryNdk_initSentryNative( sentry_transport_free(transport); } sentry_options_free(options); + return (jint) -1; } JNIEXPORT void JNICALL