From 42df453c6020e2d9656ed230b205631b7f102a08 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Mon, 5 Feb 2024 08:44:56 +0100 Subject: [PATCH 01/11] POC: Move NDK code to sentry-natice --- .gitmodules | 3 - build.gradle.kts | 1 + sentry-android-ndk/CMakeLists.txt | 17 - sentry-android-ndk/api/sentry-android-ndk.api | 2 +- sentry-android-ndk/build.gradle.kts | 31 +- sentry-android-ndk/sentry-native | 1 - .../sentry/android/ndk/DebugImagesLoader.java | 18 +- .../io/sentry/android/ndk/INativeScope.java | 18 - .../android/ndk/NativeModuleListLoader.java | 19 - .../io/sentry/android/ndk/NativeScope.java | 55 -- .../sentry/android/ndk/NdkScopeObserver.java | 2 + .../java/io/sentry/android/ndk/SentryNdk.java | 32 +- sentry-android-ndk/src/main/jni/sentry.c | 494 ------------------ .../sentry-samples-android/CMakeLists.txt | 4 +- .../src/main/cpp/native-sample.cpp | 14 +- settings.gradle.kts | 9 - 16 files changed, 45 insertions(+), 675 deletions(-) delete mode 100644 sentry-android-ndk/CMakeLists.txt delete mode 160000 sentry-android-ndk/sentry-native delete mode 100644 sentry-android-ndk/src/main/java/io/sentry/android/ndk/INativeScope.java delete mode 100644 sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeModuleListLoader.java delete mode 100644 sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeScope.java delete mode 100644 sentry-android-ndk/src/main/jni/sentry.c diff --git a/.gitmodules b/.gitmodules index fe6c3b7cc0..e69de29bb2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "sentry-android-ndk/sentry-native"] - path = sentry-android-ndk/sentry-native - url = https://github.com/getsentry/sentry-native diff --git a/build.gradle.kts b/build.gradle.kts index 3f255d4c40..928c23df55 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -78,6 +78,7 @@ allprojects { repositories { google() mavenCentral() + mavenLocal() } group = Config.Sentry.group version = properties[Config.Sentry.versionNameProp].toString() diff --git a/sentry-android-ndk/CMakeLists.txt b/sentry-android-ndk/CMakeLists.txt deleted file mode 100644 index c9a0181935..0000000000 --- a/sentry-android-ndk/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 3.10) -project(Sentry-Android LANGUAGES C CXX) - -# Add sentry-android shared library -add_library(sentry-android SHARED src/main/jni/sentry.c) - -# make sure that we build it as a shared lib instead of a static lib -set(BUILD_SHARED_LIBS ON) -set(SENTRY_BUILD_SHARED_LIBS ON) - -# Adding sentry-native submodule subdirectory -add_subdirectory(${SENTRY_NATIVE_SRC} sentry_build) - -# Link to sentry-native -target_link_libraries(sentry-android PRIVATE - $ -) diff --git a/sentry-android-ndk/api/sentry-android-ndk.api b/sentry-android-ndk/api/sentry-android-ndk.api index e8f838ce8b..155a368b11 100644 --- a/sentry-android-ndk/api/sentry-android-ndk.api +++ b/sentry-android-ndk/api/sentry-android-ndk.api @@ -7,7 +7,7 @@ public final class io/sentry/android/ndk/BuildConfig { } public final class io/sentry/android/ndk/DebugImagesLoader : io/sentry/android/core/IDebugImagesLoader { - public fun (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/ndk/NativeModuleListLoader;)V + public fun (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/ndk/NativeModuleListLoader;)V public fun clearDebugImages ()V public fun loadDebugImages ()Ljava/util/List; } diff --git a/sentry-android-ndk/build.gradle.kts b/sentry-android-ndk/build.gradle.kts index f6564cd97f..cb1d98c8d5 100644 --- a/sentry-android-ndk/build.gradle.kts +++ b/sentry-android-ndk/build.gradle.kts @@ -9,34 +9,18 @@ plugins { id(Config.QualityPlugins.gradleVersions) } -var sentryNativeSrc: String = "sentry-native" val sentryAndroidSdkName: String by project android { compileSdk = Config.Android.compileSdkVersion namespace = "io.sentry.android.ndk" - sentryNativeSrc = if (File("${project.projectDir}/sentry-native-local").exists()) { - "sentry-native-local" - } else { - "sentry-native" - } - println("sentry-android-ndk: $sentryNativeSrc") - defaultConfig { targetSdk = Config.Android.targetSdkVersion minSdk = Config.Android.minSdkVersionNdk // NDK requires a higher API level than core. testInstrumentationRunner = Config.TestLibs.androidJUnitRunner - externalNativeBuild { - cmake { - arguments.add(0, "-DANDROID_STL=c++_static") - arguments.add(0, "-DSENTRY_NATIVE_SRC=$sentryNativeSrc") - arguments.add(0, "-DSENTRY_SDK_NAME=$sentryAndroidSdkName") - } - } - ndk { abiFilters.addAll(Config.Android.abiFilters) } @@ -45,15 +29,6 @@ android { buildConfigField("String", "VERSION_NAME", "\"${project.version}\"") } - // we use the default NDK and CMake versions based on the AGP's version - // https://developer.android.com/studio/projects/install-ndk#apply-specific-version - - externalNativeBuild { - cmake { - path("CMakeLists.txt") - } - } - buildTypes { getByName("debug") getByName("release") { @@ -81,10 +56,6 @@ android { checkReleaseBuilds = false } - nativeBundleExport { - headerDir = "${project.projectDir}/$sentryNativeSrc/include" - } - // needed because of Kotlin 1.4.x configurations.all { resolutionStrategy.force(Config.CompileOnly.jetbrainsAnnotations) @@ -101,6 +72,8 @@ dependencies { api(projects.sentry) api(projects.sentryAndroidCore) + implementation("io.sentry:sentry-native-ndk:1.0.1") + compileOnly(Config.CompileOnly.jetbrainsAnnotations) testImplementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION)) diff --git a/sentry-android-ndk/sentry-native b/sentry-android-ndk/sentry-native deleted file mode 160000 index 4ec95c0725..0000000000 --- a/sentry-android-ndk/sentry-native +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4ec95c0725df5f34440db8fa8d37b4c519fce74e diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/DebugImagesLoader.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/DebugImagesLoader.java index cb38db498a..2e069dcc74 100644 --- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/DebugImagesLoader.java +++ b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/DebugImagesLoader.java @@ -4,9 +4,10 @@ import io.sentry.SentryOptions; import io.sentry.android.core.IDebugImagesLoader; import io.sentry.android.core.SentryAndroidOptions; +import io.sentry.ndk.NativeModuleListLoader; import io.sentry.protocol.DebugImage; import io.sentry.util.Objects; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,9 +46,20 @@ public DebugImagesLoader( synchronized (debugImagesLock) { if (debugImages == null) { try { - final DebugImage[] debugImagesArr = moduleListLoader.loadModuleList(); + final io.sentry.ndk.DebugImage[] debugImagesArr = moduleListLoader.loadModuleList(); if (debugImagesArr != null) { - debugImages = Arrays.asList(debugImagesArr); + debugImages = new ArrayList<>(debugImagesArr.length); + for (io.sentry.ndk.DebugImage d : debugImagesArr) { + final DebugImage debugImage = new DebugImage(); + debugImage.setUuid(d.getUuid()); + debugImage.setType(d.getType()); + debugImage.setDebugId(d.getDebugId()); + debugImage.setCodeId(d.getCodeId()); + debugImage.setImageAddr(d.getImageAddr()); + debugImage.setImageSize(d.getImageSize()); + debugImage.setArch(d.getArch()); + debugImages.add(debugImage); + } options .getLogger() .log(SentryLevel.DEBUG, "Debug images loaded: %d", debugImages.size()); diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/INativeScope.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/INativeScope.java deleted file mode 100644 index a8d50e40fe..0000000000 --- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/INativeScope.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.sentry.android.ndk; - -interface INativeScope { - void setTag(String key, String value); - - void removeTag(String key); - - void setExtra(String key, String value); - - void removeExtra(String key); - - void setUser(String id, String email, String ipAddress, String username); - - void removeUser(); - - void addBreadcrumb( - String level, String message, String category, String type, String timestamp, String data); -} diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeModuleListLoader.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeModuleListLoader.java deleted file mode 100644 index 464fcd3992..0000000000 --- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeModuleListLoader.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.sentry.android.ndk; - -import io.sentry.protocol.DebugImage; -import org.jetbrains.annotations.Nullable; - -final class NativeModuleListLoader { - - public @Nullable DebugImage[] loadModuleList() { - return nativeLoadModuleList(); - } - - public void clearModuleList() { - nativeClearModuleList(); - } - - public static native DebugImage[] nativeLoadModuleList(); - - public static native void nativeClearModuleList(); -} diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeScope.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeScope.java deleted file mode 100644 index 9d82f9d5c8..0000000000 --- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NativeScope.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.sentry.android.ndk; - -final class NativeScope implements INativeScope { - @Override - public void setTag(String key, String value) { - nativeSetTag(key, value); - } - - @Override - public void removeTag(String key) { - nativeRemoveTag(key); - } - - @Override - public void setExtra(String key, String value) { - nativeSetExtra(key, value); - } - - @Override - public void removeExtra(String key) { - nativeRemoveExtra(key); - } - - @Override - public void setUser(String id, String email, String ipAddress, String username) { - nativeSetUser(id, email, ipAddress, username); - } - - @Override - public void removeUser() { - nativeRemoveUser(); - } - - @Override - public void addBreadcrumb( - String level, String message, String category, String type, String timestamp, String data) { - nativeAddBreadcrumb(level, message, category, type, timestamp, data); - } - - public static native void nativeSetTag(String key, String value); - - public static native void nativeRemoveTag(String key); - - public static native void nativeSetExtra(String key, String value); - - public static native void nativeRemoveExtra(String key); - - public static native void nativeSetUser( - String id, String email, String ipAddress, String username); - - public static native void nativeRemoveUser(); - - public static native void nativeAddBreadcrumb( - String level, String message, String category, String type, String timestamp, String data); -} diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java index 009bba9b81..4a4237ba08 100644 --- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java +++ b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/NdkScopeObserver.java @@ -5,6 +5,8 @@ import io.sentry.ScopeObserverAdapter; import io.sentry.SentryLevel; import io.sentry.SentryOptions; +import io.sentry.ndk.INativeScope; +import io.sentry.ndk.NativeScope; import io.sentry.protocol.User; import io.sentry.util.Objects; import java.util.Locale; diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java index 1ddc04c524..ebce1a12fd 100644 --- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java +++ b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java @@ -1,6 +1,8 @@ package io.sentry.android.ndk; import io.sentry.android.core.SentryAndroidOptions; +import io.sentry.ndk.NativeModuleListLoader; +import io.sentry.ndk.NdkOptions; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -9,21 +11,6 @@ public final class SentryNdk { private SentryNdk() {} - static { - // On older Android versions, it was necessary to manually call "`System.loadLibrary` on all - // transitive dependencies before loading [the] main library." - // The dependencies of `libsentry.so` are currently `lib{c,m,dl,log}.so`. - // See - // https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-dependency-resolution - System.loadLibrary("log"); - System.loadLibrary("sentry"); - System.loadLibrary("sentry-android"); - } - - private static native void initSentryNative(@NotNull final SentryAndroidOptions options); - - private static native void shutdown(); - /** * Init the NDK integration * @@ -31,7 +18,18 @@ private SentryNdk() {} */ public static void init(@NotNull final SentryAndroidOptions options) { SentryNdkUtil.addPackage(options.getSdkVersion()); - initSentryNative(options); + + final @NotNull NdkOptions ndkOptions = + new NdkOptions( + options.getDsn(), + options.isDebug(), + options.getOutboxPath(), + options.getRelease(), + options.getEnvironment(), + options.getDist(), + options.getMaxBreadcrumbs(), + options.getNativeSdkName()); + io.sentry.ndk.SentryNdk.init(ndkOptions); // only add scope sync observer if the scope sync is enabled. if (options.isEnableScopeSync()) { @@ -43,6 +41,6 @@ public static void init(@NotNull final SentryAndroidOptions options) { /** Closes the NDK integration */ public static void close() { - shutdown(); + io.sentry.ndk.SentryNdk.close(); } } diff --git a/sentry-android-ndk/src/main/jni/sentry.c b/sentry-android-ndk/src/main/jni/sentry.c deleted file mode 100644 index d62ef56123..0000000000 --- a/sentry-android-ndk/src/main/jni/sentry.c +++ /dev/null @@ -1,494 +0,0 @@ -#include -#include -#include -#include -#include - -#define ENSURE(Expr) \ - if (!(Expr)) \ - return - -#define ENSURE_OR_FAIL(Expr) \ - if (!(Expr)) \ - goto fail - -static bool get_string_into(JNIEnv *env, jstring jstr, char* buf, size_t buf_len) -{ - jsize utf_len = (*env)->GetStringUTFLength(env, jstr); - if ((size_t)utf_len >= buf_len) { - return false; - } - - jsize j_len = (*env)->GetStringLength(env, jstr); - - (*env)->GetStringUTFRegion(env, jstr, 0, j_len, buf); - if ((*env)->ExceptionCheck(env) == JNI_TRUE) { - return false; - } - - buf[utf_len] = '\0'; - return true; -} - -static char* get_string(JNIEnv *env, jstring jstr) { - char *buf = NULL; - - jsize utf_len = (*env)->GetStringUTFLength(env, jstr); - size_t buf_len = (size_t)utf_len + 1; - buf = sentry_malloc(buf_len); - ENSURE_OR_FAIL(buf); - - ENSURE_OR_FAIL(get_string_into(env, jstr, buf, buf_len)); - - return buf; - -fail: - sentry_free(buf); - - return NULL; -} - -static char *call_get_string(JNIEnv *env, jobject obj, jmethodID mid) -{ - jstring j_str = (jstring)(*env)->CallObjectMethod(env, obj, mid); - ENSURE_OR_FAIL(j_str); - char* str = get_string(env, j_str); - (*env)->DeleteLocalRef(env, j_str); - - return str; - -fail: - return NULL; -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeScope_nativeSetTag( - JNIEnv *env, - jclass cls, - jstring key, - jstring value) { - const char *charKey = (*env)->GetStringUTFChars(env, key, 0); - const char *charValue = (*env)->GetStringUTFChars(env, value, 0); - - sentry_set_tag(charKey, charValue); - - (*env)->ReleaseStringUTFChars(env, key, charKey); - (*env)->ReleaseStringUTFChars(env, value, charValue); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeScope_nativeRemoveTag(JNIEnv *env, jclass cls, jstring key) { - const char *charKey = (*env)->GetStringUTFChars(env, key, 0); - - sentry_remove_tag(charKey); - - (*env)->ReleaseStringUTFChars(env, key, charKey); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeScope_nativeSetExtra( - JNIEnv *env, - jclass cls, - jstring key, - jstring value) { - const char *charKey = (*env)->GetStringUTFChars(env, key, 0); - const char *charValue = (*env)->GetStringUTFChars(env, value, 0); - - sentry_value_t sentryValue = sentry_value_new_string(charValue); - sentry_set_extra(charKey, sentryValue); - - (*env)->ReleaseStringUTFChars(env, key, charKey); - (*env)->ReleaseStringUTFChars(env, value, charValue); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeScope_nativeRemoveExtra(JNIEnv *env, jclass cls, jstring key) { - const char *charKey = (*env)->GetStringUTFChars(env, key, 0); - - sentry_remove_extra(charKey); - - (*env)->ReleaseStringUTFChars(env, key, charKey); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeScope_nativeSetUser( - JNIEnv *env, - jclass cls, - jstring id, - jstring email, - jstring ipAddress, - jstring username) { - sentry_value_t user = sentry_value_new_object(); - if (id) { - const char *charId = (*env)->GetStringUTFChars(env, id, 0); - sentry_value_set_by_key(user, "id", sentry_value_new_string(charId)); - (*env)->ReleaseStringUTFChars(env, id, charId); - } - if (email) { - const char *charEmail = (*env)->GetStringUTFChars(env, email, 0); - sentry_value_set_by_key( - user, "email", sentry_value_new_string(charEmail)); - (*env)->ReleaseStringUTFChars(env, email, charEmail); - } - if (ipAddress) { - const char *charIpAddress = (*env)->GetStringUTFChars(env, ipAddress, 0); - sentry_value_set_by_key( - user, "ip_address", sentry_value_new_string(charIpAddress)); - (*env)->ReleaseStringUTFChars(env, ipAddress, charIpAddress); - } - if (username) { - const char *charUsername = (*env)->GetStringUTFChars(env, username, 0); - sentry_value_set_by_key( - user, "username", sentry_value_new_string(charUsername)); - (*env)->ReleaseStringUTFChars(env, username, charUsername); - } - sentry_set_user(user); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeScope_nativeRemoveUser(JNIEnv *env, jclass cls) { - sentry_remove_user(); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeScope_nativeAddBreadcrumb( - JNIEnv *env, - jclass cls, - jstring level, - jstring message, - jstring category, - jstring type, - jstring timestamp, - jstring data) { - if (!level && !message && !category && !type) { - return; - } - const char *charMessage = NULL; - if (message) { - charMessage = (*env)->GetStringUTFChars(env, message, 0); - } - const char *charType = NULL; - if (type) { - charType = (*env)->GetStringUTFChars(env, type, 0); - } - sentry_value_t crumb = sentry_value_new_breadcrumb(charType, charMessage); - - if (charMessage) { - (*env)->ReleaseStringUTFChars(env, message, charMessage); - } - if (charType) { - (*env)->ReleaseStringUTFChars(env, type, charType); - } - - if (category) { - const char *charCategory = (*env)->GetStringUTFChars(env, category, 0); - sentry_value_set_by_key( - crumb, "category", sentry_value_new_string(charCategory)); - (*env)->ReleaseStringUTFChars(env, category, charCategory); - } - if (level) { - const char *charLevel = (*env)->GetStringUTFChars(env, level, 0); - sentry_value_set_by_key( - crumb, "level", sentry_value_new_string(charLevel)); - (*env)->ReleaseStringUTFChars(env, level, charLevel); - } - - if (timestamp) { - // overwrite timestamp that is already created on sentry_value_new_breadcrumb - const char *charTimestamp = (*env)->GetStringUTFChars(env, timestamp, 0); - sentry_value_set_by_key( - crumb, "timestamp", sentry_value_new_string(charTimestamp)); - (*env)->ReleaseStringUTFChars(env, timestamp, charTimestamp); - } - - if (data) { - const char *charData = (*env)->GetStringUTFChars(env, data, 0); - - // we create an object because the Java layer parses it as a Map - sentry_value_t dataObject = sentry_value_new_object(); - sentry_value_set_by_key(dataObject, "data", sentry_value_new_string(charData)); - - sentry_value_set_by_key(crumb, "data", dataObject); - - (*env)->ReleaseStringUTFChars(env, data, charData); - } - - sentry_add_breadcrumb(crumb); -} - -static void send_envelope(sentry_envelope_t *envelope, void *data) { - const char *outbox_path = (const char *) data; - char envelope_id_str[40]; - - sentry_uuid_t envelope_id = sentry_uuid_new_v4(); - sentry_uuid_as_string(&envelope_id, envelope_id_str); - - size_t outbox_len = strlen(outbox_path); - size_t final_len = outbox_len + 42; // "/" + envelope_id_str + "\0" = 42 - char* envelope_path = sentry_malloc(final_len); - ENSURE(envelope_path); - int written = snprintf(envelope_path, final_len, "%s/%s", outbox_path, envelope_id_str); - if (written > outbox_len && written < final_len) { - sentry_envelope_write_to_file(envelope, envelope_path); - } - - sentry_free(envelope_path); - sentry_envelope_free(envelope); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_SentryNdk_initSentryNative( - JNIEnv *env, - jclass cls, - jobject sentry_sdk_options) { - jclass options_cls = (*env)->GetObjectClass(env, sentry_sdk_options); - jmethodID outbox_path_mid = (*env)->GetMethodID(env, options_cls, "getOutboxPath", - "()Ljava/lang/String;"); - jmethodID dsn_mid = (*env)->GetMethodID(env, options_cls, "getDsn", "()Ljava/lang/String;"); - jmethodID is_debug_mid = (*env)->GetMethodID(env, options_cls, "isDebug", "()Z"); - jmethodID release_mid = (*env)->GetMethodID(env, options_cls, "getRelease", - "()Ljava/lang/String;"); - jmethodID environment_mid = (*env)->GetMethodID(env, options_cls, "getEnvironment", - "()Ljava/lang/String;"); - jmethodID dist_mid = (*env)->GetMethodID(env, options_cls, "getDist", "()Ljava/lang/String;"); - jmethodID max_crumbs_mid = (*env)->GetMethodID(env, options_cls, "getMaxBreadcrumbs", "()I"); - jmethodID native_sdk_name_mid = (*env)->GetMethodID(env, options_cls, "getNativeSdkName", - "()Ljava/lang/String;"); - - (*env)->DeleteLocalRef(env, options_cls); - - char *outbox_path = NULL; - sentry_transport_t *transport = NULL; - bool transport_owns_path = false; - sentry_options_t *options = NULL; - bool options_owns_transport = false; - char *dsn_str = NULL; - char *release_str = NULL; - char *environment_str = NULL; - char *dist_str = NULL; - char *native_sdk_name_str = NULL; - - options = sentry_options_new(); - ENSURE_OR_FAIL(options); - - // session tracking is enabled by default, but the Android SDK already handles it - sentry_options_set_auto_session_tracking(options, 0); - - jboolean debug = (jboolean)(*env)->CallBooleanMethod(env, sentry_sdk_options, is_debug_mid); - sentry_options_set_debug(options, debug); - - jint max_crumbs = (jint) (*env)->CallIntMethod(env, sentry_sdk_options, max_crumbs_mid); - sentry_options_set_max_breadcrumbs(options, max_crumbs); - - outbox_path = call_get_string(env, sentry_sdk_options, outbox_path_mid); - ENSURE_OR_FAIL(outbox_path); - - transport = sentry_transport_new(send_envelope); - ENSURE_OR_FAIL(transport); - sentry_transport_set_state(transport, outbox_path); - sentry_transport_set_free_func(transport, sentry_free); - transport_owns_path = true; - - sentry_options_set_transport(options, transport); - options_owns_transport = true; - - // give sentry-native its own database path it can work with, next to the outbox - size_t outbox_len = strlen(outbox_path); - size_t final_len = outbox_len + 15; // len(".sentry-native\0") = 15 - char* database_path = sentry_malloc(final_len); - ENSURE_OR_FAIL(database_path); - strncpy(database_path, outbox_path, final_len); - char *dir = strrchr(database_path, '/'); - if (dir) - { - strncpy(dir + 1, ".sentry-native", final_len - (dir + 1 - database_path)); - } - sentry_options_set_database_path(options, database_path); - sentry_free(database_path); - - dsn_str = call_get_string(env, sentry_sdk_options, dsn_mid); - ENSURE_OR_FAIL(dsn_str); - sentry_options_set_dsn(options, dsn_str); - sentry_free(dsn_str); - - release_str = call_get_string(env, sentry_sdk_options, release_mid); - if (release_str) { - sentry_options_set_release(options, release_str); - sentry_free(release_str); - } - - environment_str = call_get_string(env, sentry_sdk_options, environment_mid); - if (environment_str) - { - sentry_options_set_environment(options, environment_str); - sentry_free(environment_str); - } - - dist_str = call_get_string(env, sentry_sdk_options, dist_mid); - if (dist_str) - { - sentry_options_set_dist(options, dist_str); - sentry_free(dist_str); - } - - native_sdk_name_str = call_get_string(env, sentry_sdk_options, native_sdk_name_mid); - if (native_sdk_name_str) { - sentry_options_set_sdk_name(options, native_sdk_name_str); - sentry_free(native_sdk_name_str); - } - - sentry_init(options); - return; - -fail: - if (!transport_owns_path) { - sentry_free(outbox_path); - } - if (!options_owns_transport) { - sentry_transport_free(transport); - } - sentry_options_free(options); -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_NativeModuleListLoader_nativeClearModuleList(JNIEnv *env, jclass cls) { - sentry_clear_modulecache(); -} - -JNIEXPORT jobjectArray JNICALL -Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *env, jclass cls) { - sentry_value_t image_list_t = sentry_get_modules_list(); - jobjectArray image_list = NULL; - - if (sentry_value_get_type(image_list_t) == SENTRY_VALUE_TYPE_LIST) { - size_t len_t = sentry_value_get_length(image_list_t); - - jclass image_class = (*env)->FindClass(env, "io/sentry/protocol/DebugImage"); - image_list = (*env)->NewObjectArray(env, len_t, image_class, NULL); - - jmethodID image_addr_method = (*env)->GetMethodID(env, image_class, "setImageAddr", - "(Ljava/lang/String;)V"); - - jmethodID image_size_method = (*env)->GetMethodID(env, image_class, "setImageSize", - "(J)V"); - - jmethodID code_file_method = (*env)->GetMethodID(env, image_class, "setCodeFile", - "(Ljava/lang/String;)V"); - - jmethodID image_addr_ctor = (*env)->GetMethodID(env, image_class, "", - "()V"); - - jmethodID type_method = (*env)->GetMethodID(env, image_class, "setType", - "(Ljava/lang/String;)V"); - - jmethodID debug_id_method = (*env)->GetMethodID(env, image_class, "setDebugId", - "(Ljava/lang/String;)V"); - - jmethodID code_id_method = (*env)->GetMethodID(env, image_class, "setCodeId", - "(Ljava/lang/String;)V"); - - jmethodID debug_file_method = (*env)->GetMethodID(env, image_class, "setDebugFile", - "(Ljava/lang/String;)V"); - - for (size_t i = 0; i < len_t; i++) { - sentry_value_t image_t = sentry_value_get_by_index(image_list_t, i); - - if (!sentry_value_is_null(image_t)) { - jobject image = (*env)->NewObject(env, image_class, image_addr_ctor); - - sentry_value_t image_addr_t = sentry_value_get_by_key(image_t, "image_addr"); - if (!sentry_value_is_null(image_addr_t)) { - - const char *value_v = sentry_value_as_string(image_addr_t); - jstring value = (*env)->NewStringUTF(env, value_v); - - (*env)->CallVoidMethod(env, image, image_addr_method, value); - - // Local refs (eg NewStringUTF) are freed automatically when the native method - // returns, but if you're iterating a large array, it's recommended to release - // manually due to allocation limits (512) on Android < 8 or OOM. - // https://developer.android.com/training/articles/perf-jni.html#local-and-global-references - (*env)->DeleteLocalRef(env, value); - } - - sentry_value_t image_size_t = sentry_value_get_by_key(image_t, "image_size"); - if (!sentry_value_is_null(image_size_t)) { - - int32_t value_v = sentry_value_as_int32(image_size_t); - jlong value = (jlong) value_v; - - (*env)->CallVoidMethod(env, image, image_size_method, value); - } - - sentry_value_t code_file_t = sentry_value_get_by_key(image_t, "code_file"); - if (!sentry_value_is_null(code_file_t)) { - - const char *value_v = sentry_value_as_string(code_file_t); - jstring value = (*env)->NewStringUTF(env, value_v); - - (*env)->CallVoidMethod(env, image, code_file_method, value); - - (*env)->DeleteLocalRef(env, value); - } - - sentry_value_t code_type_t = sentry_value_get_by_key(image_t, "type"); - if (!sentry_value_is_null(code_type_t)) { - - const char *value_v = sentry_value_as_string(code_type_t); - jstring value = (*env)->NewStringUTF(env, value_v); - - (*env)->CallVoidMethod(env, image, type_method, value); - - (*env)->DeleteLocalRef(env, value); - } - - sentry_value_t debug_id_t = sentry_value_get_by_key(image_t, "debug_id"); - if (!sentry_value_is_null(code_type_t)) { - - const char *value_v = sentry_value_as_string(debug_id_t); - jstring value = (*env)->NewStringUTF(env, value_v); - - (*env)->CallVoidMethod(env, image, debug_id_method, value); - - (*env)->DeleteLocalRef(env, value); - } - - sentry_value_t code_id_t = sentry_value_get_by_key(image_t, "code_id"); - if (!sentry_value_is_null(code_id_t)) { - - const char *value_v = sentry_value_as_string(code_id_t); - jstring value = (*env)->NewStringUTF(env, value_v); - - (*env)->CallVoidMethod(env, image, code_id_method, value); - - (*env)->DeleteLocalRef(env, value); - } - - // not needed on Android, but keeping for forward compatibility - sentry_value_t debug_file_t = sentry_value_get_by_key(image_t, "debug_file"); - if (!sentry_value_is_null(debug_file_t)) { - - const char *value_v = sentry_value_as_string(debug_file_t); - jstring value = (*env)->NewStringUTF(env, value_v); - - (*env)->CallVoidMethod(env, image, debug_file_method, value); - - (*env)->DeleteLocalRef(env, value); - } - - (*env)->SetObjectArrayElement(env, image_list, i, image); - - (*env)->DeleteLocalRef(env, image); - } - } - - sentry_value_decref(image_list_t); - } - - return image_list; -} - -JNIEXPORT void JNICALL -Java_io_sentry_android_ndk_SentryNdk_shutdown(JNIEnv *env, jclass cls) { - sentry_close(); -} diff --git a/sentry-samples/sentry-samples-android/CMakeLists.txt b/sentry-samples/sentry-samples-android/CMakeLists.txt index ad170fe404..115e1f9672 100644 --- a/sentry-samples/sentry-samples-android/CMakeLists.txt +++ b/sentry-samples/sentry-samples-android/CMakeLists.txt @@ -7,11 +7,11 @@ add_library(native-sample SHARED src/main/cpp/native-sample.cpp) set(BUILD_SHARED_LIBS ON) set(SENTRY_BUILD_SHARED_LIBS ON) -add_subdirectory(../../sentry-android-ndk/${SENTRY_NATIVE_SRC} sentry_build) +#add_subdirectory(../../sentry-android-ndk/${SENTRY_NATIVE_SRC} sentry_build) find_library(LOG_LIB log) target_link_libraries(native-sample PRIVATE ${LOG_LIB} - $ + # $ ) diff --git a/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp b/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp index 2a31e6c6e5..f30d936670 100644 --- a/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp +++ b/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp @@ -1,6 +1,6 @@ #include #include -#include +// #include #define TAG "sentry-sample" @@ -14,12 +14,12 @@ JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_crash(JNIEnv JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_message(JNIEnv *env, jclass cls) { __android_log_print(ANDROID_LOG_WARN, TAG, "Sending message."); - sentry_value_t event = sentry_value_new_message_event( - /* level */ SENTRY_LEVEL_INFO, - /* logger */ "custom", - /* message */ "It works!" - ); - sentry_capture_event(event); +// sentry_value_t event = sentry_value_new_message_event( +// /* level */ SENTRY_LEVEL_INFO, +// /* logger */ "custom", +// /* message */ "It works!" +// ); +// sentry_capture_event(event); } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 028037372d..b6de6741ed 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -66,12 +66,3 @@ include( "sentry-android-integration-tests:test-app-sentry", "sentry-samples:sentry-samples-openfeign" ) - -gradle.beforeProject { - if (project.name == "sentry-android-ndk" || project.name == "sentry-samples-android") { - exec { - logger.log(LogLevel.LIFECYCLE, "Initializing git submodules") - commandLine("git", "submodule", "update", "--init", "--recursive") - } - } -} From 6f72a25fa3d80e83782fb9ab0865ab0ce71e0bbc Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Mon, 5 Feb 2024 17:20:50 +0100 Subject: [PATCH 02/11] temp --- buildSrc/src/main/java/Config.kt | 3 ++- sentry-android-ndk/build.gradle.kts | 2 +- .../sentry-samples-android/CMakeLists.txt | 6 +++--- .../sentry-samples-android/build.gradle.kts | 11 ++--------- .../src/main/cpp/native-sample.cpp | 14 +++++++------- sentry/src/main/java/io/sentry/JsonSerializer.java | 2 +- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index 7a0081d5f4..082a080a09 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -256,7 +256,8 @@ object Config { } object NativePlugins { - val nativeBundlePlugin = "io.github.howardpang:androidNativeBundle:1.1.1" + val nativeBundlePlugin = "io.github.howardpang:androidNativeBundle:1.1.4" val nativeBundleExport = "com.ydq.android.gradle.native-aar.export" + val nativeImport = "com.ydq.android.gradle.native-aar.import" } } diff --git a/sentry-android-ndk/build.gradle.kts b/sentry-android-ndk/build.gradle.kts index cb1d98c8d5..2c412c56ba 100644 --- a/sentry-android-ndk/build.gradle.kts +++ b/sentry-android-ndk/build.gradle.kts @@ -72,7 +72,7 @@ dependencies { api(projects.sentry) api(projects.sentryAndroidCore) - implementation("io.sentry:sentry-native-ndk:1.0.1") + implementation("io.sentry:sentry-native-ndk:1.0.4") compileOnly(Config.CompileOnly.jetbrainsAnnotations) diff --git a/sentry-samples/sentry-samples-android/CMakeLists.txt b/sentry-samples/sentry-samples-android/CMakeLists.txt index 115e1f9672..2060e06149 100644 --- a/sentry-samples/sentry-samples-android/CMakeLists.txt +++ b/sentry-samples/sentry-samples-android/CMakeLists.txt @@ -3,15 +3,15 @@ project(Sentry-Sample LANGUAGES C CXX) add_library(native-sample SHARED src/main/cpp/native-sample.cpp) +find_package(sentry-android REQUIRED CONFIG) + # make sure that we build it as a shared lib instead of a static lib set(BUILD_SHARED_LIBS ON) set(SENTRY_BUILD_SHARED_LIBS ON) -#add_subdirectory(../../sentry-android-ndk/${SENTRY_NATIVE_SRC} sentry_build) - find_library(LOG_LIB log) target_link_libraries(native-sample PRIVATE ${LOG_LIB} - # $ +# sentry-android::sentry-android ) diff --git a/sentry-samples/sentry-samples-android/build.gradle.kts b/sentry-samples/sentry-samples-android/build.gradle.kts index ac77791268..46d2475eff 100644 --- a/sentry-samples/sentry-samples-android/build.gradle.kts +++ b/sentry-samples/sentry-samples-android/build.gradle.kts @@ -15,16 +15,8 @@ android { versionName = project.version.toString() externalNativeBuild { - val sentryNativeSrc = if (File("${project.projectDir}/../../sentry-android-ndk/sentry-native-local").exists()) { - "sentry-native-local" - } else { - "sentry-native" - } - println("sentry-samples-android: $sentryNativeSrc") - cmake { - arguments.add(0, "-DANDROID_STL=c++_static") - arguments.add(0, "-DSENTRY_NATIVE_SRC=$sentryNativeSrc") + arguments.add(0, "-DANDROID_STL=c++_shared") } } @@ -38,6 +30,7 @@ android { // Note that the viewBinding.enabled property is now deprecated. viewBinding = true compose = true + prefab = true } composeOptions { diff --git a/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp b/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp index f30d936670..2a31e6c6e5 100644 --- a/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp +++ b/sentry-samples/sentry-samples-android/src/main/cpp/native-sample.cpp @@ -1,6 +1,6 @@ #include #include -// #include +#include #define TAG "sentry-sample" @@ -14,12 +14,12 @@ JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_crash(JNIEnv JNIEXPORT void JNICALL Java_io_sentry_samples_android_NativeSample_message(JNIEnv *env, jclass cls) { __android_log_print(ANDROID_LOG_WARN, TAG, "Sending message."); -// sentry_value_t event = sentry_value_new_message_event( -// /* level */ SENTRY_LEVEL_INFO, -// /* logger */ "custom", -// /* message */ "It works!" -// ); -// sentry_capture_event(event); + sentry_value_t event = sentry_value_new_message_event( + /* level */ SENTRY_LEVEL_INFO, + /* logger */ "custom", + /* message */ "It works!" + ); + sentry_capture_event(event); } } diff --git a/sentry/src/main/java/io/sentry/JsonSerializer.java b/sentry/src/main/java/io/sentry/JsonSerializer.java index c22eb095b5..7e4b4791b0 100644 --- a/sentry/src/main/java/io/sentry/JsonSerializer.java +++ b/sentry/src/main/java/io/sentry/JsonSerializer.java @@ -178,7 +178,7 @@ public JsonSerializer(@NotNull SentryOptions options) { // Serialize @Override - public void serialize(@NotNull T entity, @NotNull Writer writer) throws IOException { + public void serialize(@NotNull T entity, @NotNull Writer write r) throws IOException { Objects.requireNonNull(entity, "The entity is required."); Objects.requireNonNull(writer, "The Writer object is required."); From 46be3d102b9f868f0003fd80a0429a4141deab06 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Tue, 30 Apr 2024 15:18:07 +0200 Subject: [PATCH 03/11] Fix prefab setup, minor cleanup --- build.gradle.kts | 4 ---- buildSrc/src/main/java/Config.kt | 6 ------ sentry-android-ndk/build.gradle.kts | 3 +-- sentry-samples/sentry-samples-android/CMakeLists.txt | 9 +++------ sentry-samples/sentry-samples-android/build.gradle.kts | 2 ++ 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c403513581..ff9e45b869 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,10 +32,6 @@ buildscript { classpath(Config.QualityPlugins.errorpronePlugin) classpath(Config.QualityPlugins.gradleVersionsPlugin) - // add classpath of androidNativeBundle - // com.ydq.android.gradle.build.tool:nativeBundle:{version}} - classpath(Config.NativePlugins.nativeBundlePlugin) - // add classpath of sentry android gradle plugin // classpath("io.sentry:sentry-android-gradle-plugin:{version}") diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index 082a080a09..31c99bad3f 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -254,10 +254,4 @@ object Config { val errorprone = "com.google.errorprone:error_prone_core:2.11.0" val errorProneNullAway = "com.uber.nullaway:nullaway:0.9.5" } - - object NativePlugins { - val nativeBundlePlugin = "io.github.howardpang:androidNativeBundle:1.1.4" - val nativeBundleExport = "com.ydq.android.gradle.native-aar.export" - val nativeImport = "com.ydq.android.gradle.native-aar.import" - } } diff --git a/sentry-android-ndk/build.gradle.kts b/sentry-android-ndk/build.gradle.kts index 2c412c56ba..aaf5b99499 100644 --- a/sentry-android-ndk/build.gradle.kts +++ b/sentry-android-ndk/build.gradle.kts @@ -5,7 +5,6 @@ plugins { kotlin("android") jacoco id(Config.QualityPlugins.jacocoAndroid) - id(Config.NativePlugins.nativeBundleExport) id(Config.QualityPlugins.gradleVersions) } @@ -72,7 +71,7 @@ dependencies { api(projects.sentry) api(projects.sentryAndroidCore) - implementation("io.sentry:sentry-native-ndk:1.0.4") + implementation("io.sentry:sentry-native-ndk:0.7.20") compileOnly(Config.CompileOnly.jetbrainsAnnotations) diff --git a/sentry-samples/sentry-samples-android/CMakeLists.txt b/sentry-samples/sentry-samples-android/CMakeLists.txt index 2060e06149..e6e096bec3 100644 --- a/sentry-samples/sentry-samples-android/CMakeLists.txt +++ b/sentry-samples/sentry-samples-android/CMakeLists.txt @@ -3,15 +3,12 @@ project(Sentry-Sample LANGUAGES C CXX) add_library(native-sample SHARED src/main/cpp/native-sample.cpp) -find_package(sentry-android REQUIRED CONFIG) - -# make sure that we build it as a shared lib instead of a static lib -set(BUILD_SHARED_LIBS ON) -set(SENTRY_BUILD_SHARED_LIBS ON) +find_package(sentry-ndk REQUIRED CONFIG) find_library(LOG_LIB log) target_link_libraries(native-sample PRIVATE ${LOG_LIB} -# sentry-android::sentry-android + sentry-ndk::sentry-android + sentry-ndk::sentry ) diff --git a/sentry-samples/sentry-samples-android/build.gradle.kts b/sentry-samples/sentry-samples-android/build.gradle.kts index 46d2475eff..d642df77f0 100644 --- a/sentry-samples/sentry-samples-android/build.gradle.kts +++ b/sentry-samples/sentry-samples-android/build.gradle.kts @@ -126,4 +126,6 @@ dependencies { implementation(Config.Libs.composeMaterial) debugImplementation(Config.Libs.leakCanary) + + implementation("io.sentry:sentry-native-ndk:0.7.20") } From 8d99942cfd4eb5da8b309ae8c06750fd194c76cc Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Wed, 8 May 2024 10:04:58 +0200 Subject: [PATCH 04/11] Fix typo --- sentry/src/main/java/io/sentry/JsonSerializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry/src/main/java/io/sentry/JsonSerializer.java b/sentry/src/main/java/io/sentry/JsonSerializer.java index 5603de7127..022a3d2044 100644 --- a/sentry/src/main/java/io/sentry/JsonSerializer.java +++ b/sentry/src/main/java/io/sentry/JsonSerializer.java @@ -180,7 +180,7 @@ public JsonSerializer(@NotNull SentryOptions options) { // Serialize @Override - public void serialize(@NotNull T entity, @NotNull Writer write r) throws IOException { + public void serialize(@NotNull T entity, @NotNull Writer writer) throws IOException { Objects.requireNonNull(entity, "The entity is required."); Objects.requireNonNull(writer, "The Writer object is required."); From 4367e617e82dede2a680cc680cc449e707f947f5 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Wed, 8 May 2024 12:15:07 +0200 Subject: [PATCH 05/11] Use proper package names --- sentry-samples/sentry-samples-android/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sentry-samples/sentry-samples-android/CMakeLists.txt b/sentry-samples/sentry-samples-android/CMakeLists.txt index e6e096bec3..19dca2b80d 100644 --- a/sentry-samples/sentry-samples-android/CMakeLists.txt +++ b/sentry-samples/sentry-samples-android/CMakeLists.txt @@ -3,12 +3,12 @@ project(Sentry-Sample LANGUAGES C CXX) add_library(native-sample SHARED src/main/cpp/native-sample.cpp) -find_package(sentry-ndk REQUIRED CONFIG) +find_package(sentry-native-ndk REQUIRED CONFIG) find_library(LOG_LIB log) target_link_libraries(native-sample PRIVATE ${LOG_LIB} - sentry-ndk::sentry-android - sentry-ndk::sentry + sentry-native-ndk::sentry-android + sentry-native-ndk::sentry ) From 019d16f8cb0bf81d8434248d6a007c6eae1afa46 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Fri, 24 May 2024 10:40:44 +0200 Subject: [PATCH 06/11] Switch to shell script for updating sentry-native --- .github/workflows/update-deps.yml | 2 +- scripts/update-sentry-native-ndk.sh | 33 +++++++++++++++++++++++++++++ sentry-android-ndk/build.gradle.kts | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 scripts/update-sentry-native-ndk.sh diff --git a/.github/workflows/update-deps.yml b/.github/workflows/update-deps.yml index 24fce64050..83d90bb919 100644 --- a/.github/workflows/update-deps.yml +++ b/.github/workflows/update-deps.yml @@ -13,7 +13,7 @@ jobs: native: uses: getsentry/github-workflows/.github/workflows/updater.yml@v2 with: - path: sentry-android-ndk/sentry-native + path: scripts/update-sentry-native-ndk.sh name: Native SDK secrets: # If a custom token is used instead, a CI would be triggered on a created PR. diff --git a/scripts/update-sentry-native-ndk.sh b/scripts/update-sentry-native-ndk.sh new file mode 100755 index 0000000000..438f0ac068 --- /dev/null +++ b/scripts/update-sentry-native-ndk.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd $(dirname "$0")/../ +GRADLE_FILEPATH=sentry-android-ndk/build.gradle.kts + +case $1 in +get-version) + version=$(perl -ne 'print "$1\n" if ( m/io\.sentry:sentry-native-ndk:([0-9.]+)+/ )' $GRADLE_FILEPATH) + + echo "v$version" + ;; +get-repo) + echo "https://github.com/getsentry/sentry-native.git" + ;; +set-version) + version=$2 + + # Remove leading "v" + if [[ "$version" == v* ]]; then + version="${version:1}" + fi + + echo "Setting sentry-native-ndk version to '$version'" + + PATTERN="io\.sentry:sentry-native-ndk:([0-9.]+)+" + perl -pi -e "s/$PATTERN/io.sentry:sentry-native-ndk:$version/g" $GRADLE_FILEPATH + ;; +*) + echo "Unknown argument $1" + exit 1 + ;; +esac diff --git a/sentry-android-ndk/build.gradle.kts b/sentry-android-ndk/build.gradle.kts index aaf5b99499..2608532694 100644 --- a/sentry-android-ndk/build.gradle.kts +++ b/sentry-android-ndk/build.gradle.kts @@ -71,7 +71,7 @@ dependencies { api(projects.sentry) api(projects.sentryAndroidCore) - implementation("io.sentry:sentry-native-ndk:0.7.20") + implementation("io.sentry:sentry-native-ndk:0.7.4") compileOnly(Config.CompileOnly.jetbrainsAnnotations) From aa3376d28c067cd85a26804eed77d9d0aeb13fcf Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Fri, 24 May 2024 10:46:12 +0200 Subject: [PATCH 07/11] Update ndk sample as well --- scripts/update-sentry-native-ndk.sh | 8 +++++--- sentry-samples/sentry-samples-android/build.gradle.kts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/update-sentry-native-ndk.sh b/scripts/update-sentry-native-ndk.sh index 438f0ac068..544dc403ac 100755 --- a/scripts/update-sentry-native-ndk.sh +++ b/scripts/update-sentry-native-ndk.sh @@ -2,11 +2,12 @@ set -euo pipefail cd $(dirname "$0")/../ -GRADLE_FILEPATH=sentry-android-ndk/build.gradle.kts +GRADLE_NDK_FILEPATH=sentry-android-ndk/build.gradle.kts +GRADLE_SAMPLE_FILEPATH=sentry-samples/sentry-samples-android/build.gradle.kts case $1 in get-version) - version=$(perl -ne 'print "$1\n" if ( m/io\.sentry:sentry-native-ndk:([0-9.]+)+/ )' $GRADLE_FILEPATH) + version=$(perl -ne 'print "$1\n" if ( m/io\.sentry:sentry-native-ndk:([0-9.]+)+/ )' $GRADLE_NDK_FILEPATH) echo "v$version" ;; @@ -24,7 +25,8 @@ set-version) echo "Setting sentry-native-ndk version to '$version'" PATTERN="io\.sentry:sentry-native-ndk:([0-9.]+)+" - perl -pi -e "s/$PATTERN/io.sentry:sentry-native-ndk:$version/g" $GRADLE_FILEPATH + perl -pi -e "s/$PATTERN/io.sentry:sentry-native-ndk:$version/g" $GRADLE_NDK_FILEPATH + perl -pi -e "s/$PATTERN/io.sentry:sentry-native-ndk:$version/g" $GRADLE_SAMPLE_FILEPATH ;; *) echo "Unknown argument $1" diff --git a/sentry-samples/sentry-samples-android/build.gradle.kts b/sentry-samples/sentry-samples-android/build.gradle.kts index d642df77f0..bbd641d750 100644 --- a/sentry-samples/sentry-samples-android/build.gradle.kts +++ b/sentry-samples/sentry-samples-android/build.gradle.kts @@ -127,5 +127,5 @@ dependencies { debugImplementation(Config.Libs.leakCanary) - implementation("io.sentry:sentry-native-ndk:0.7.20") + implementation("io.sentry:sentry-native-ndk:0.7.4") } From 6f76b85ad00dbf4cdd16fb604562d4f65502257a Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Fri, 24 May 2024 10:55:02 +0200 Subject: [PATCH 08/11] Add Changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1900c51541..7e461ca11a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +- (Android) The JNI layer for sentry-native has now been moved from sentry-java to sentry-native ([#3189](https://github.com/getsentry/sentry-java/pull/3189)) + - This now includes prefab support for sentry-native, allowing you to link and access the sentry-native API within your native app code + - Checkout the `sentry-samples/sentry-samples-android` example on how to configure CMake and consume `sentry.h` + - The prebuilt libsentry.so and libsentry-android.so libraries are now compiled using the ANDROID_STL=c++_shared flag, making it easier to use on wider set of configurations + ## 8.0.0-alpha.1 Version 8 of the Sentry Android/Java SDK brings a variety of features and fixes. The most notable changes are: From 7cb177f389ef4b49386adc09f931117e89ff75bd Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Fri, 24 May 2024 13:25:35 +0200 Subject: [PATCH 09/11] Fix tests --- .../test/java/io/sentry/android/ndk/DebugImagesLoaderTest.kt | 5 ++--- .../test/java/io/sentry/android/ndk/NdkScopeObserverTest.kt | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/DebugImagesLoaderTest.kt b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/DebugImagesLoaderTest.kt index db584c814f..927ce98c3b 100644 --- a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/DebugImagesLoaderTest.kt +++ b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/DebugImagesLoaderTest.kt @@ -1,11 +1,10 @@ package io.sentry.android.ndk import io.sentry.android.core.SentryAndroidOptions -import io.sentry.protocol.DebugImage +import io.sentry.ndk.NativeModuleListLoader import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -import java.lang.RuntimeException import kotlin.test.Test import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -38,7 +37,7 @@ class DebugImagesLoaderTest { whenever(fixture.nativeLoader.loadModuleList()).thenReturn(arrayOf()) assertNotNull(sut.loadDebugImages()) - whenever(fixture.nativeLoader.loadModuleList()).thenReturn(arrayOf(DebugImage())) + whenever(fixture.nativeLoader.loadModuleList()).thenReturn(arrayOf(io.sentry.ndk.DebugImage())) assertTrue(sut.loadDebugImages()!!.isEmpty()) } diff --git a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/NdkScopeObserverTest.kt b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/NdkScopeObserverTest.kt index 335a7679e1..ad523a883e 100644 --- a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/NdkScopeObserverTest.kt +++ b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/NdkScopeObserverTest.kt @@ -5,6 +5,7 @@ import io.sentry.DateUtils import io.sentry.JsonSerializer import io.sentry.SentryLevel import io.sentry.SentryOptions +import io.sentry.ndk.INativeScope import io.sentry.protocol.User import org.mockito.kotlin.eq import org.mockito.kotlin.mock From a694d81f73648b721bb2ff4cb4d5b6fd83c28972 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Tue, 28 May 2024 14:22:23 +0200 Subject: [PATCH 10/11] Bump sentry-native to 0.7.5 --- sentry-android-ndk/build.gradle.kts | 2 +- sentry-samples/sentry-samples-android/build.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry-android-ndk/build.gradle.kts b/sentry-android-ndk/build.gradle.kts index 2608532694..fe67063139 100644 --- a/sentry-android-ndk/build.gradle.kts +++ b/sentry-android-ndk/build.gradle.kts @@ -71,7 +71,7 @@ dependencies { api(projects.sentry) api(projects.sentryAndroidCore) - implementation("io.sentry:sentry-native-ndk:0.7.4") + implementation("io.sentry:sentry-native-ndk:0.7.5") compileOnly(Config.CompileOnly.jetbrainsAnnotations) diff --git a/sentry-samples/sentry-samples-android/build.gradle.kts b/sentry-samples/sentry-samples-android/build.gradle.kts index bbd641d750..3723c3df2b 100644 --- a/sentry-samples/sentry-samples-android/build.gradle.kts +++ b/sentry-samples/sentry-samples-android/build.gradle.kts @@ -127,5 +127,5 @@ dependencies { debugImplementation(Config.Libs.leakCanary) - implementation("io.sentry:sentry-native-ndk:0.7.4") + implementation("io.sentry:sentry-native-ndk:0.7.5") } From aa8a95553732f245a270f6ddb8794fc5120aaac1 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Tue, 28 May 2024 14:25:24 +0200 Subject: [PATCH 11/11] Update Changelog --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e461ca11a..40b46e53e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,17 @@ ## Unreleased +### Behavioural Changes + - (Android) The JNI layer for sentry-native has now been moved from sentry-java to sentry-native ([#3189](https://github.com/getsentry/sentry-java/pull/3189)) - This now includes prefab support for sentry-native, allowing you to link and access the sentry-native API within your native app code - Checkout the `sentry-samples/sentry-samples-android` example on how to configure CMake and consume `sentry.h` - - The prebuilt libsentry.so and libsentry-android.so libraries are now compiled using the ANDROID_STL=c++_shared flag, making it easier to use on wider set of configurations + +### Dependencies + +- Bump Native SDK from v0.7.0 to v0.7.5 ([#3441](https://github.com/getsentry/sentry-java/pull/3189)) + - [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#075) + - [diff](https://github.com/getsentry/sentry-native/compare/0.7.0...0.7.5) ## 8.0.0-alpha.1