diff --git a/ndk/Makefile b/ndk/Makefile new file mode 100644 index 000000000..eef6c97b0 --- /dev/null +++ b/ndk/Makefile @@ -0,0 +1,21 @@ +.PHONY: all clean compile format api check + +all: clean format compile api check + +clean: + ./gradlew clean + +compile: + ./gradlew build + +# Format code using the spotless gradle plugin +format: + ./gradlew spotlessApply + +# Creates the .api dump file +api: + ./gradlew :sentry-native-ndk:apiDump + +# Run tests and lint +check: + ./gradlew check diff --git a/ndk/build.gradle.kts b/ndk/build.gradle.kts index 4e9ded034..d12f10d60 100644 --- a/ndk/build.gradle.kts +++ b/ndk/build.gradle.kts @@ -1,3 +1,4 @@ +import com.diffplug.gradle.spotless.SpotlessPlugin import com.diffplug.spotless.LineEnding import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.MavenPublishPlugin @@ -9,11 +10,10 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { `java-library` - id("com.diffplug.spotless") version "6.11.0" apply true + id("com.diffplug.spotless") version "6.25.0" apply true id("io.gitlab.arturbosch.detekt") version "1.19.0" `maven-publish` id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.0" - } buildscript { @@ -46,11 +46,12 @@ allprojects { withType { testLogging.showStandardStreams = true testLogging.exceptionFormat = TestExceptionFormat.FULL - testLogging.events = setOf( - TestLogEvent.SKIPPED, - TestLogEvent.PASSED, - TestLogEvent.FAILED - ) + testLogging.events = + setOf( + TestLogEvent.SKIPPED, + TestLogEvent.PASSED, + TestLogEvent.FAILED, + ) maxParallelForks = Runtime.getRuntime().availableProcessors() / 2 // Cap JVM args per test @@ -59,7 +60,7 @@ allprojects { dependsOn("cleanTest") } withType { - options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile", "-Xlint:-processing")) + options.compilerArgs.addAll(arrayOf("-Xlint:all", "-Werror", "-Xlint:-classfile", "-Xlint:-processing", "-Xlint:-options")) } } } @@ -127,6 +128,8 @@ subprojects { } } } + + apply() } spotless { @@ -139,21 +142,25 @@ spotless { } kotlin { target("**/*.kt") + targetExclude("**/generated/**") ktlint() } kotlinGradle { target("**/*.kts") + targetExclude("**/generated/**") ktlint() } } -private val androidLibs = setOf( - "lib" -) +private val androidLibs = + setOf( + "lib", + ) -private val androidXLibs = listOf( - "androidx.core:core" -) +private val androidXLibs = + listOf( + "androidx.core:core", + ) /* * Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549 @@ -178,22 +185,25 @@ private val androidXLibs = listOf( fun MavenPublishBaseExtension.assignAarTypes() { pom { withXml { - val dependencies = asNode().children().find { - it is Node && it.name().toString().endsWith("dependencies") - } as Node? + val dependencies = + asNode().children().find { + it is Node && it.name().toString().endsWith("dependencies") + } as Node? dependencies?.children()?.forEach { dep -> if (dep !is Node) { return@forEach } - val group = dep.children().firstOrNull { - it is Node && it.name().toString().endsWith("groupId") - } as? Node + val group = + dep.children().firstOrNull { + it is Node && it.name().toString().endsWith("groupId") + } as? Node val groupValue = group?.children()?.firstOrNull() as? String - val artifactId = dep.children().firstOrNull { - it is Node && it.name().toString().endsWith("artifactId") - } as? Node + val artifactId = + dep.children().firstOrNull { + it is Node && it.name().toString().endsWith("artifactId") + } as? Node val artifactIdValue = artifactId?.children()?.firstOrNull() as? String if (artifactIdValue in androidLibs) { @@ -205,3 +215,7 @@ fun MavenPublishBaseExtension.assignAarTypes() { } } } + +apiValidation { + ignoredProjects.addAll(listOf("sample")) +} diff --git a/ndk/gradle.properties b/ndk/gradle.properties index 994f367ad..56e13e378 100644 --- a/ndk/gradle.properties +++ b/ndk/gradle.properties @@ -51,3 +51,5 @@ POM_ARTIFACT_ID=sentry-native-ndk systemProp.org.gradle.internal.http.socketTimeout=120000 android.nonTransitiveRClass=true + +android.suppressUnsupportedCompileSdk=34 diff --git a/ndk/lib/api/sentry-android-ndk.api b/ndk/lib/api/sentry-android-ndk.api deleted file mode 100644 index e8f838ce8..000000000 --- a/ndk/lib/api/sentry-android-ndk.api +++ /dev/null @@ -1,29 +0,0 @@ -public final class io/sentry/android/ndk/BuildConfig { - public static final field BUILD_TYPE Ljava/lang/String; - public static final field DEBUG Z - public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; - public static final field VERSION_NAME Ljava/lang/String; - public fun ()V -} - -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 clearDebugImages ()V - public fun loadDebugImages ()Ljava/util/List; -} - -public final class io/sentry/android/ndk/NdkScopeObserver : io/sentry/ScopeObserverAdapter { - public fun (Lio/sentry/SentryOptions;)V - public fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public fun removeExtra (Ljava/lang/String;)V - public fun removeTag (Ljava/lang/String;)V - public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V - public fun setTag (Ljava/lang/String;Ljava/lang/String;)V - public fun setUser (Lio/sentry/protocol/User;)V -} - -public final class io/sentry/android/ndk/SentryNdk { - public static fun close ()V - public static fun init (Lio/sentry/android/core/SentryAndroidOptions;)V -} - diff --git a/ndk/lib/api/sentry-native-ndk.api b/ndk/lib/api/sentry-native-ndk.api new file mode 100644 index 000000000..8dca41c08 --- /dev/null +++ b/ndk/lib/api/sentry-native-ndk.api @@ -0,0 +1,83 @@ +public final class io/sentry/ndk/BuildConfig { + public static final field BUILD_TYPE Ljava/lang/String; + public static final field DEBUG Z + public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; + public fun ()V +} + +public final class io/sentry/ndk/DebugImage { + public fun ()V + public fun getArch ()Ljava/lang/String; + public fun getCodeFile ()Ljava/lang/String; + public fun getCodeId ()Ljava/lang/String; + public fun getDebugFile ()Ljava/lang/String; + public fun getDebugId ()Ljava/lang/String; + public fun getImageAddr ()Ljava/lang/String; + public fun getImageSize ()Ljava/lang/Long; + public fun getType ()Ljava/lang/String; + public fun getUuid ()Ljava/lang/String; + public fun setArch (Ljava/lang/String;)V + public fun setCodeFile (Ljava/lang/String;)V + public fun setCodeId (Ljava/lang/String;)V + public fun setDebugFile (Ljava/lang/String;)V + public fun setDebugId (Ljava/lang/String;)V + public fun setImageAddr (Ljava/lang/String;)V + public fun setImageSize (J)V + public fun setImageSize (Ljava/lang/Long;)V + public fun setType (Ljava/lang/String;)V + public fun setUuid (Ljava/lang/String;)V +} + +public abstract interface class io/sentry/ndk/INativeScope { + public abstract fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public abstract fun removeExtra (Ljava/lang/String;)V + public abstract fun removeTag (Ljava/lang/String;)V + public abstract fun removeUser ()V + public abstract fun setExtra (Ljava/lang/String;Ljava/lang/String;)V + public abstract fun setTag (Ljava/lang/String;Ljava/lang/String;)V + public abstract fun setUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V +} + +public final class io/sentry/ndk/NativeModuleListLoader { + public fun ()V + public fun clearModuleList ()V + public fun loadModuleList ()[Lio/sentry/ndk/DebugImage; + public static fun nativeClearModuleList ()V + public static fun nativeLoadModuleList ()[Lio/sentry/ndk/DebugImage; +} + +public final class io/sentry/ndk/NativeScope : io/sentry/ndk/INativeScope { + public fun ()V + public fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public static fun nativeAddBreadcrumb (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public static fun nativeRemoveExtra (Ljava/lang/String;)V + public static fun nativeRemoveTag (Ljava/lang/String;)V + public static fun nativeRemoveUser ()V + public static fun nativeSetExtra (Ljava/lang/String;Ljava/lang/String;)V + public static fun nativeSetTag (Ljava/lang/String;Ljava/lang/String;)V + public static fun nativeSetUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + public fun removeExtra (Ljava/lang/String;)V + public fun removeTag (Ljava/lang/String;)V + public fun removeUser ()V + public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V + public fun setTag (Ljava/lang/String;Ljava/lang/String;)V + public fun setUser (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V +} + +public final class io/sentry/ndk/NdkOptions { + public fun (Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V + public fun getDist ()Ljava/lang/String; + public fun getDsn ()Ljava/lang/String; + public fun getEnvironment ()Ljava/lang/String; + public fun getMaxBreadcrumbs ()I + public fun getOutboxPath ()Ljava/lang/String; + public fun getRelease ()Ljava/lang/String; + public fun getSdkName ()Ljava/lang/String; + public fun isDebug ()Z +} + +public final class io/sentry/ndk/SentryNdk { + public static fun close ()V + public static fun init (Lio/sentry/ndk/NdkOptions;)V +} + diff --git a/ndk/lib/src/main/java/io/sentry/ndk/DebugImage.java b/ndk/lib/src/main/java/io/sentry/ndk/DebugImage.java index e06b6e2b4..1819f0b37 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/DebugImage.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/DebugImage.java @@ -1,199 +1,203 @@ package io.sentry.ndk; -import org.jetbrains.annotations.Nullable; - import java.util.Map; +import org.jetbrains.annotations.Nullable; public final class DebugImage { - /** - * The unique UUID of the image. - * - *

UUID computed from the file contents, assigned by the Java SDK. - */ - private @Nullable String uuid; - - private @Nullable String type; - /** - * Unique debug identifier of the image. - * - *

- `elf`: Debug identifier of the dynamic library or executable. If a code identifier is - * available, the debug identifier is the little-endian UUID representation of the first 16-bytes - * of that identifier. Spaces are inserted for readability, note the byte order of the first - * fields: - * - *

```text code id: f1c3bcc0 2798 65fe 3058 404b2831d9e6 4135386c debug id: - * c0bcc3f1-9827-fe65-3058-404b2831d9e6 ``` - * - *

If no code id is available, the debug id should be computed by XORing the first 4096 bytes - * of the `.text` section in 16-byte chunks, and representing it as a little-endian UUID (again - * swapping the byte order). - * - *

- `pe`: `signature` and `age` of the PDB file. Both values can be read from the CodeView - * PDB70 debug information header in the PE. The value should be represented as little-endian - * UUID, with the age appended at the end. Note that the byte order of the UUID fields must be - * swapped (spaces inserted for readability): - * - *

```text signature: f1c3bcc0 2798 65fe 3058 404b2831d9e6 age: 1 debug_id: - * c0bcc3f1-9827-fe65-3058-404b2831d9e6-1 ``` - * - *

- `macho`: Identifier of the dynamic library or executable. It is the value of the `LC_UUID` - * load command in the Mach header, formatted as UUID. - */ - private @Nullable String debugId; - - /** - * Path and name of the debug companion file. - * - *

- `elf`: Name or absolute path to the file containing stripped debug information for this - * image. This value might be _required_ to retrieve debug files from certain symbol servers. - * - *

- `pe`: Name of the PDB file containing debug information for this image. This value is - * often required to retrieve debug files from specific symbol servers. - * - *

- `macho`: Name or absolute path to the dSYM file containing debug information for this - * image. This value might be required to retrieve debug files from certain symbol servers. - */ - private @Nullable String debugFile; - /** - * Optional identifier of the code file. - * - *

- `elf`: If the program was compiled with a relatively recent compiler, this should be the - * hex representation of the `NT_GNU_BUILD_ID` program header (type `PT_NOTE`), or the value of - * the `.note.gnu.build-id` note section (type `SHT_NOTE`). Otherwise, leave this value empty. - * - *

Certain symbol servers use the code identifier to locate debug information for ELF images, - * in which case this field should be included if possible. - * - *

- `pe`: Identifier of the executable or DLL. It contains the values of the `time_date_stamp` - * from the COFF header and `size_of_image` from the optional header formatted together into a hex - * string using `%08x%X` (note that the second value is not padded): - * - *

```text time_date_stamp: 0x5ab38077 size_of_image: 0x9000 code_id: 5ab380779000 ``` - * - *

The code identifier should be provided to allow server-side stack walking of binary crash - * reports, such as Minidumps. - * - *

- * - *

- `macho`: Identifier of the dynamic library or executable. It is the value of the `LC_UUID` - * load command in the Mach header, formatted as UUID. Can be empty for Mach images, as it is - * equivalent to the debug identifier. - */ - private @Nullable String codeId; - /** - * Path and name of the image file (required). - * - *

The absolute path to the dynamic library or executable. This helps to locate the file if it - * is missing on Sentry. - * - *

- `pe`: The code file should be provided to allow server-side stack walking of binary crash - * reports, such as Minidumps. - */ - private @Nullable String codeFile; - /** - * Starting memory address of the image (required). - * - *

Memory address, at which the image is mounted in the virtual address space of the process. - * Should be a string in hex representation prefixed with `"0x"`. - */ - private @Nullable String imageAddr; - /** - * Size of the image in bytes (required). - * - *

The size of the image in virtual memory. If missing, Sentry will assume that the image spans - * up to the next image, which might lead to invalid stack traces. - */ - private @Nullable Long imageSize; - /** - * CPU architecture target. - * - *

Architecture of the module. If missing, this will be backfilled by Sentry. - */ - private @Nullable String arch; - - @SuppressWarnings("unused") - private @Nullable Map unknown; - - public @Nullable String getUuid() { - return uuid; - } - - public void setUuid(final @Nullable String uuid) { - this.uuid = uuid; - } - - public @Nullable String getType() { - return type; - } - - public void setType(final @Nullable String type) { - this.type = type; - } - - public @Nullable String getDebugId() { - return debugId; - } - - public void setDebugId(final @Nullable String debugId) { - this.debugId = debugId; - } - - public @Nullable String getDebugFile() { - return debugFile; - } - - public void setDebugFile(final @Nullable String debugFile) { - this.debugFile = debugFile; - } - - public @Nullable String getCodeFile() { - return codeFile; - } - - public void setCodeFile(final @Nullable String codeFile) { - this.codeFile = codeFile; - } - - public @Nullable String getImageAddr() { - return imageAddr; - } - - public void setImageAddr(final @Nullable String imageAddr) { - this.imageAddr = imageAddr; - } - - public @Nullable Long getImageSize() { - return imageSize; - } - - public void setImageSize(final @Nullable Long imageSize) { - this.imageSize = imageSize; - } - - /** - * Sets the image size. - * - * @param imageSize the image size. - */ - public void setImageSize(long imageSize) { - this.imageSize = imageSize; - } - - public @Nullable String getArch() { - return arch; - } - - public void setArch(final @Nullable String arch) { - this.arch = arch; - } - - public @Nullable String getCodeId() { - return codeId; - } - - public void setCodeId(final @Nullable String codeId) { - this.codeId = codeId; - } - + /** + * The unique UUID of the image. + * + *

UUID computed from the file contents, assigned by the Java SDK. + */ + private @Nullable String uuid; + + private @Nullable String type; + + /** + * Unique debug identifier of the image. + * + *

- `elf`: Debug identifier of the dynamic library or executable. If a code identifier is + * available, the debug identifier is the little-endian UUID representation of the first 16-bytes + * of that identifier. Spaces are inserted for readability, note the byte order of the first + * fields: + * + *

```text code id: f1c3bcc0 2798 65fe 3058 404b2831d9e6 4135386c debug id: + * c0bcc3f1-9827-fe65-3058-404b2831d9e6 ``` + * + *

If no code id is available, the debug id should be computed by XORing the first 4096 bytes + * of the `.text` section in 16-byte chunks, and representing it as a little-endian UUID (again + * swapping the byte order). + * + *

- `pe`: `signature` and `age` of the PDB file. Both values can be read from the CodeView + * PDB70 debug information header in the PE. The value should be represented as little-endian + * UUID, with the age appended at the end. Note that the byte order of the UUID fields must be + * swapped (spaces inserted for readability): + * + *

```text signature: f1c3bcc0 2798 65fe 3058 404b2831d9e6 age: 1 debug_id: + * c0bcc3f1-9827-fe65-3058-404b2831d9e6-1 ``` + * + *

- `macho`: Identifier of the dynamic library or executable. It is the value of the `LC_UUID` + * load command in the Mach header, formatted as UUID. + */ + private @Nullable String debugId; + + /** + * Path and name of the debug companion file. + * + *

- `elf`: Name or absolute path to the file containing stripped debug information for this + * image. This value might be _required_ to retrieve debug files from certain symbol servers. + * + *

- `pe`: Name of the PDB file containing debug information for this image. This value is + * often required to retrieve debug files from specific symbol servers. + * + *

- `macho`: Name or absolute path to the dSYM file containing debug information for this + * image. This value might be required to retrieve debug files from certain symbol servers. + */ + private @Nullable String debugFile; + + /** + * Optional identifier of the code file. + * + *

- `elf`: If the program was compiled with a relatively recent compiler, this should be the + * hex representation of the `NT_GNU_BUILD_ID` program header (type `PT_NOTE`), or the value of + * the `.note.gnu.build-id` note section (type `SHT_NOTE`). Otherwise, leave this value empty. + * + *

Certain symbol servers use the code identifier to locate debug information for ELF images, + * in which case this field should be included if possible. + * + *

- `pe`: Identifier of the executable or DLL. It contains the values of the `time_date_stamp` + * from the COFF header and `size_of_image` from the optional header formatted together into a hex + * string using `%08x%X` (note that the second value is not padded): + * + *

```text time_date_stamp: 0x5ab38077 size_of_image: 0x9000 code_id: 5ab380779000 ``` + * + *

The code identifier should be provided to allow server-side stack walking of binary crash + * reports, such as Minidumps. + * + *

+ * + *

- `macho`: Identifier of the dynamic library or executable. It is the value of the `LC_UUID` + * load command in the Mach header, formatted as UUID. Can be empty for Mach images, as it is + * equivalent to the debug identifier. + */ + private @Nullable String codeId; + + /** + * Path and name of the image file (required). + * + *

The absolute path to the dynamic library or executable. This helps to locate the file if it + * is missing on Sentry. + * + *

- `pe`: The code file should be provided to allow server-side stack walking of binary crash + * reports, such as Minidumps. + */ + private @Nullable String codeFile; + + /** + * Starting memory address of the image (required). + * + *

Memory address, at which the image is mounted in the virtual address space of the process. + * Should be a string in hex representation prefixed with `"0x"`. + */ + private @Nullable String imageAddr; + + /** + * Size of the image in bytes (required). + * + *

The size of the image in virtual memory. If missing, Sentry will assume that the image spans + * up to the next image, which might lead to invalid stack traces. + */ + private @Nullable Long imageSize; + + /** + * CPU architecture target. + * + *

Architecture of the module. If missing, this will be backfilled by Sentry. + */ + private @Nullable String arch; + + @SuppressWarnings("unused") + private @Nullable Map unknown; + + public @Nullable String getUuid() { + return uuid; + } + + public void setUuid(final @Nullable String uuid) { + this.uuid = uuid; + } + + public @Nullable String getType() { + return type; + } + + public void setType(final @Nullable String type) { + this.type = type; + } + + public @Nullable String getDebugId() { + return debugId; + } + + public void setDebugId(final @Nullable String debugId) { + this.debugId = debugId; + } + + public @Nullable String getDebugFile() { + return debugFile; + } + + public void setDebugFile(final @Nullable String debugFile) { + this.debugFile = debugFile; + } + + public @Nullable String getCodeFile() { + return codeFile; + } + + public void setCodeFile(final @Nullable String codeFile) { + this.codeFile = codeFile; + } + + public @Nullable String getImageAddr() { + return imageAddr; + } + + public void setImageAddr(final @Nullable String imageAddr) { + this.imageAddr = imageAddr; + } + + public @Nullable Long getImageSize() { + return imageSize; + } + + public void setImageSize(final @Nullable Long imageSize) { + this.imageSize = imageSize; + } + + /** + * Sets the image size. + * + * @param imageSize the image size. + */ + public void setImageSize(long imageSize) { + this.imageSize = imageSize; + } + + public @Nullable String getArch() { + return arch; + } + + public void setArch(final @Nullable String arch) { + this.arch = arch; + } + + public @Nullable String getCodeId() { + return codeId; + } + + public void setCodeId(final @Nullable String codeId) { + this.codeId = codeId; + } } diff --git a/ndk/lib/src/main/java/io/sentry/ndk/INativeScope.java b/ndk/lib/src/main/java/io/sentry/ndk/INativeScope.java index 4053929b3..f56ed47be 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/INativeScope.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/INativeScope.java @@ -1,18 +1,18 @@ package io.sentry.ndk; public interface INativeScope { - void setTag(String key, String value); + void setTag(String key, String value); - void removeTag(String key); + void removeTag(String key); - void setExtra(String key, String value); + void setExtra(String key, String value); - void removeExtra(String key); + void removeExtra(String key); - void setUser(String id, String email, String ipAddress, String username); + void setUser(String id, String email, String ipAddress, String username); - void removeUser(); + void removeUser(); - void addBreadcrumb( - String level, String message, String category, String type, String timestamp, String data); + void addBreadcrumb( + String level, String message, String category, String type, String timestamp, String data); } diff --git a/ndk/lib/src/main/java/io/sentry/ndk/NativeModuleListLoader.java b/ndk/lib/src/main/java/io/sentry/ndk/NativeModuleListLoader.java index c6612cef7..0e268bae8 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/NativeModuleListLoader.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/NativeModuleListLoader.java @@ -4,15 +4,15 @@ public final class NativeModuleListLoader { - public static native DebugImage[] nativeLoadModuleList(); + public static native DebugImage[] nativeLoadModuleList(); - public static native void nativeClearModuleList(); + public static native void nativeClearModuleList(); - public @Nullable DebugImage[] loadModuleList() { - return nativeLoadModuleList(); - } + public @Nullable DebugImage[] loadModuleList() { + return nativeLoadModuleList(); + } - public void clearModuleList() { - nativeClearModuleList(); - } + public void clearModuleList() { + nativeClearModuleList(); + } } diff --git a/ndk/lib/src/main/java/io/sentry/ndk/NativeScope.java b/ndk/lib/src/main/java/io/sentry/ndk/NativeScope.java index 18df418f7..c5abddc90 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/NativeScope.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/NativeScope.java @@ -1,55 +1,55 @@ package io.sentry.ndk; public final class NativeScope implements INativeScope { - public static native void nativeSetTag(String key, String value); + public static native void nativeSetTag(String key, String value); - public static native void nativeRemoveTag(String key); + public static native void nativeRemoveTag(String key); - public static native void nativeSetExtra(String key, String value); + public static native void nativeSetExtra(String key, String value); - public static native void nativeRemoveExtra(String key); + public static native void nativeRemoveExtra(String key); - public static native void nativeSetUser( - String id, String email, String ipAddress, String username); + public static native void nativeSetUser( + String id, String email, String ipAddress, String username); - public static native void nativeRemoveUser(); + public static native void nativeRemoveUser(); - public static native void nativeAddBreadcrumb( - String level, String message, String category, String type, String timestamp, String data); + public static native void nativeAddBreadcrumb( + String level, String message, String category, String type, String timestamp, String data); - @Override - public void setTag(String key, String value) { - nativeSetTag(key, value); - } + @Override + public void setTag(String key, String value) { + nativeSetTag(key, value); + } - @Override - public void removeTag(String key) { - nativeRemoveTag(key); - } + @Override + public void removeTag(String key) { + nativeRemoveTag(key); + } - @Override - public void setExtra(String key, String value) { - nativeSetExtra(key, value); - } + @Override + public void setExtra(String key, String value) { + nativeSetExtra(key, value); + } - @Override - public void removeExtra(String key) { - nativeRemoveExtra(key); - } + @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 setUser(String id, String email, String ipAddress, String username) { + nativeSetUser(id, email, ipAddress, username); + } - @Override - public void removeUser() { - nativeRemoveUser(); - } + @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); - } + @Override + public void addBreadcrumb( + String level, String message, String category, String type, String timestamp, String data) { + nativeAddBreadcrumb(level, message, category, type, timestamp, data); + } } diff --git a/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java b/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java index c4ed14f40..6a82c683f 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java @@ -4,61 +4,69 @@ import org.jetbrains.annotations.Nullable; public final class NdkOptions { - private final @NotNull String dsn; - private final boolean isDebug; - private final @NotNull String outboxPath; - private final @Nullable String release; - private final @Nullable String environment; - private final @Nullable String dist; - private final int maxBreadcrumbs; - private final @Nullable String sdkName; + private final @NotNull String dsn; + private final boolean isDebug; + private final @NotNull String outboxPath; + private final @Nullable String release; + private final @Nullable String environment; + private final @Nullable String dist; + private final int maxBreadcrumbs; + private final @Nullable String sdkName; - public NdkOptions(@NotNull String dsn, boolean isDebug, @NotNull String outboxPath, @Nullable String release, @Nullable String environment, @Nullable String dist, int maxBreadcrumbs, @Nullable String sdkName) { - this.dsn = dsn; - this.isDebug = isDebug; - this.outboxPath = outboxPath; - this.release = release; - this.environment = environment; - this.dist = dist; - this.maxBreadcrumbs = maxBreadcrumbs; - this.sdkName = sdkName; - } + public NdkOptions( + @NotNull String dsn, + boolean isDebug, + @NotNull String outboxPath, + @Nullable String release, + @Nullable String environment, + @Nullable String dist, + int maxBreadcrumbs, + @Nullable String sdkName) { + this.dsn = dsn; + this.isDebug = isDebug; + this.outboxPath = outboxPath; + this.release = release; + this.environment = environment; + this.dist = dist; + this.maxBreadcrumbs = maxBreadcrumbs; + this.sdkName = sdkName; + } - @NotNull - public String getDsn() { - return dsn; - } + @NotNull + public String getDsn() { + return dsn; + } - public boolean isDebug() { - return isDebug; - } + public boolean isDebug() { + return isDebug; + } - @NotNull - public String getOutboxPath() { - return outboxPath; - } + @NotNull + public String getOutboxPath() { + return outboxPath; + } - @Nullable - public String getRelease() { - return release; - } + @Nullable + public String getRelease() { + return release; + } - @Nullable - public String getEnvironment() { - return environment; - } + @Nullable + public String getEnvironment() { + return environment; + } - @Nullable - public String getDist() { - return dist; - } + @Nullable + public String getDist() { + return dist; + } - public int getMaxBreadcrumbs() { - return maxBreadcrumbs; - } + public int getMaxBreadcrumbs() { + return maxBreadcrumbs; + } - @Nullable - public String getSdkName() { - return sdkName; - } + @Nullable + public String getSdkName() { + return sdkName; + } } 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 58394188c..6011910db 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java @@ -6,37 +6,34 @@ @ApiStatus.Internal public final class 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 SentryNdk() { - } - - private static native void initSentryNative(@NotNull final NdkOptions options); - - private static native void shutdown(); - - /** - * Init the NDK integration - * - * @param options the SentryAndroidOptions - */ - public static void init(@NotNull final NdkOptions options) { - initSentryNative(options); - } - - /** - * Closes the NDK integration - */ - public static void close() { - shutdown(); - } + 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 SentryNdk() {} + + private static native void initSentryNative(@NotNull final NdkOptions options); + + private static native void shutdown(); + + /** + * Init the NDK integration + * + * @param options the SentryAndroidOptions + */ + public static void init(@NotNull final NdkOptions options) { + initSentryNative(options); + } + + /** Closes the NDK integration */ + public static void close() { + shutdown(); + } } diff --git a/ndk/sample/build.gradle.kts b/ndk/sample/build.gradle.kts index 2227fe1ea..32a2ec68d 100644 --- a/ndk/sample/build.gradle.kts +++ b/ndk/sample/build.gradle.kts @@ -47,15 +47,17 @@ android { getByName("release") { isMinifyEnabled = true proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro", ) signingConfig = signingConfigs.getByName("debug") // to be able to run release mode isShrinkResources = true addManifestPlaceholders( mapOf( - "sentryDebug" to false, "sentryEnvironment" to "release" - ) + "sentryDebug" to false, + "sentryEnvironment" to "release", + ), ) } } diff --git a/ndk/sample/src/main/java/io/sentry/ndk/sample/MainActivity.java b/ndk/sample/src/main/java/io/sentry/ndk/sample/MainActivity.java index d8d42b3df..871702afc 100644 --- a/ndk/sample/src/main/java/io/sentry/ndk/sample/MainActivity.java +++ b/ndk/sample/src/main/java/io/sentry/ndk/sample/MainActivity.java @@ -2,53 +2,51 @@ import android.app.Activity; import android.os.Bundle; - -import java.io.File; - import io.sentry.ndk.NdkOptions; import io.sentry.ndk.SentryNdk; +import java.io.File; public class MainActivity extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); - findViewById(R.id.init_ndk_button).setOnClickListener(v -> initNdk()); - findViewById(R.id.trigger_native_crash_button).setOnClickListener(v -> NdkSample.crash()); - findViewById(R.id.capture_message_button).setOnClickListener(v -> NdkSample.message()); - } + findViewById(R.id.init_ndk_button).setOnClickListener(v -> initNdk()); + findViewById(R.id.trigger_native_crash_button).setOnClickListener(v -> NdkSample.crash()); + findViewById(R.id.capture_message_button).setOnClickListener(v -> NdkSample.message()); + } - private void initNdk() { - final File outboxFolder = setupOutboxFolder(); - final NdkOptions options = new NdkOptions( - "https://1053864c67cc410aa1ffc9701bd6f93d@o447951.ingest.sentry.io/5428559", - BuildConfig.DEBUG, - outboxFolder.getAbsolutePath(), - "1.0.0", - "production", - BuildConfig.VERSION_NAME, - 100, - "sentry-native-jni" - ); - SentryNdk.init(options); - } + private void initNdk() { + final File outboxFolder = setupOutboxFolder(); + final NdkOptions options = + new NdkOptions( + "https://1053864c67cc410aa1ffc9701bd6f93d@o447951.ingest.sentry.io/5428559", + BuildConfig.DEBUG, + outboxFolder.getAbsolutePath(), + "1.0.0", + "production", + BuildConfig.VERSION_NAME, + 100, + "sentry-native-jni"); + SentryNdk.init(options); + } - private File setupOutboxFolder() { - // ensure we have a proper outbox directory - final File outboxDir = new File(getFilesDir(), "outbox"); - if (outboxDir.isFile()) { - final boolean deleteOk = outboxDir.delete(); - if (!deleteOk) { - throw new IllegalStateException("Failed to delete outbox file: " + outboxDir); - } - } - if (!outboxDir.exists()) { - final boolean mkdirOk = outboxDir.mkdirs(); - if (!mkdirOk) { - throw new IllegalStateException("Failed to create outbox directory: " + outboxDir); - } - } - return outboxDir; + private File setupOutboxFolder() { + // ensure we have a proper outbox directory + final File outboxDir = new File(getFilesDir(), "outbox"); + if (outboxDir.isFile()) { + final boolean deleteOk = outboxDir.delete(); + if (!deleteOk) { + throw new IllegalStateException("Failed to delete outbox file: " + outboxDir); + } + } + if (!outboxDir.exists()) { + final boolean mkdirOk = outboxDir.mkdirs(); + if (!mkdirOk) { + throw new IllegalStateException("Failed to create outbox directory: " + outboxDir); + } } + return outboxDir; + } } diff --git a/ndk/sample/src/main/java/io/sentry/ndk/sample/NdkSample.java b/ndk/sample/src/main/java/io/sentry/ndk/sample/NdkSample.java index 27fdeaf5e..c76bc6f3b 100644 --- a/ndk/sample/src/main/java/io/sentry/ndk/sample/NdkSample.java +++ b/ndk/sample/src/main/java/io/sentry/ndk/sample/NdkSample.java @@ -1,11 +1,11 @@ package io.sentry.ndk.sample; public class NdkSample { - static { - System.loadLibrary("ndk-sample"); - } + static { + System.loadLibrary("ndk-sample"); + } - public static native void crash(); + public static native void crash(); - public static native void message(); + public static native void message(); }