Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -7,6 +7,10 @@

## Unreleased

### Features

- Nav3: Add `BackStackEntryMapper.SerialName`, a convenience mapper that names back stack entries after their [serial names](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/serial-name.html) ([#6703](https://github.com/getsentry/sentry-java/pull/6703))

### Improvements

- Nav3: Record why a back stack entry is `/unknown` via an `unknown_entry_reason` next to it in the Sentry UI ([#6801](https://github.com/getsentry/sentry-java/pull/6801))
Expand Down
60 changes: 60 additions & 0 deletions gradle/dependency-matrix.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Dependency matrices that let builds compile against a stable oldest supported version, while testing
# against that version and newer, automatically-updating releases. Helps ensure our source code only uses
# APIs available in the oldest supported version, while remaining compatible with subsequent releases.
#
# Each matrix <name> defines two `[versions]`:
#
# - <name>-floor: The oldest supported version. Only changed manually via a reviewed PR.
# Should not be referenced by any `version.ref` so that Dependabot leaves it alone. Instead,
# build files should apply it explicitly, e.g., with `version { strictly(...) }`.
#
# - <name>-latestStable: The latest stable release. An unused <name>-latestStable entry in `[libraries]`
# should point to the <name>-latestStable key so that Dependabot can update it. Build files can
# select between floor and latestStable.
#
# An example:
#
# // In dependency-matrix.versions.toml
# [versions]
# example-floor = "1.0.0"
# example-latestStable = "1.5.0"
#
# [libraries]
# example-core = { module = "com.example:core" }
# example-latestStable = { module = "com.example:core", version.ref = "example-latestStable" }
#
# // In build.gradle.kts
# val testVersion =
# // CI, etc. can use -PtestExample=<version> to set the desired version.
# when (providers.gradleProperty("testExample").getOrElse("floor")) {
# "floor" -> matrixLibs.versions.example.floor.get()
# "latestStable" -> matrixLibs.versions.example.latestStable.get()
# else -> error("testExample must be floor or latestStable")
# }
#
# dependencies {
# testImplementation(matrixLibs.example.core) {
# version { strictly(testVersion) }
# }
# }
#
# Additional rules:
#
# - Never give the floor key a library entry with `version.ref`, and never protect it with a
# Dependabot `ignore` rule. Ignore rules match a dependency's group and name, so they'd also
# prevent Dependabot from bumping <name>-latestStable.
#
# - A latestStable library entry mustn't share its module with any entry or build file declaration that
# Dependabot also updates (e.g., in libs.versions.toml). Dependabot merges declarations of one
# module and bumps them all to one version. If they would collide, track a sibling artifact
# instead (e.g., `-jvm`).

[versions]
# The oldest kotlinx.serialization version sentry-android-navigation3 supports. Before changing it, read the rules under "Version floor" in
# that module's .kotlinx package README.
kotlinxSerialization-floor = "1.7.3"
kotlinxSerialization-latestStable = "1.13.0"

[libraries]
kotlinxSerialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core" }
kotlinxSerialization-latestStable = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerialization-latestStable" }
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ kotlin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotl
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
buildconfig = { id = "com.github.gmazzo.buildconfig", version = "5.6.5" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
Expand Down
5 changes: 4 additions & 1 deletion sentry-android-navigation3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
Use `SentryNavEffect` alongside your `NavDisplay` to record navigation transactions, breadcrumbs, screen names, and back stack context as
users move around your app. Configure the data you want captured via `SentryNavOptions`.

This module requires Nav3. It doesn't declare its own dependencies on Compose, lifecycle, or kotlinx.serialization, but uses the versions
your Nav3 dependency brings in.

Because Nav3 back stacks can have arbitrary key types, host apps need to provide `SentryNavEffect` with a mapping between their back stack
keys and the data Sentry should display for each (see `BackStackEntryMapper`).
keys and the data Sentry should display for each (see `BackStackEntryMapper` and the built-in `SerialName` mapper).

See the [Navigation for Android docs](https://docs.sentry.io/platforms/android/integrations/navigation/) for additional details, including
configuration, supported setups, and limitations.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
public abstract interface class io/sentry/compose/navigation3/BackStackEntryMapper {
public static final field Companion Lio/sentry/compose/navigation3/BackStackEntryMapper$Companion;
public abstract fun map (Ljava/lang/Object;)Lio/sentry/compose/navigation3/SentryBackStackEntry;
}

public final class io/sentry/compose/navigation3/BackStackEntryMapper$Companion {
public final fun getSerialName ()Lio/sentry/compose/navigation3/BackStackEntryMapper;
}

public final class io/sentry/compose/navigation3/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
Expand Down
22 changes: 21 additions & 1 deletion sentry-android-navigation3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.kotlin.serialization)
id("io.sentry.detekt")
id("io.sentry.spotless")
id("io.sentry.jdk-target")
Expand All @@ -15,6 +16,8 @@ plugins {
id("io.sentry.robolectric")
}

val kotlinxSerializationFloor = matrixLibs.versions.kotlinxSerialization.floor.get()

android {
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "io.sentry.compose.navigation3"
Expand Down Expand Up @@ -45,6 +48,8 @@ android {
// AGP 9.5 can't create the Compose Preview task without it, which breaks any
// build that creates every task, such as an LSP's Gradle import.
isIncludeAndroidResources = true
// Lets tests check that MIN_KOTLINX_SERIALIZATION_VERSION matches the catalog's floor.
all { it.systemProperty("nav3.kotlinxSerializationFloor", kotlinxSerializationFloor) }
}
}

Expand Down Expand Up @@ -72,12 +77,24 @@ android {

kotlin { explicitApi() }

// Unit tests run against the kotlinx.serialization floor by default. CI also runs them against the
// latest stable release, as apps may ship a newer kotlinx.serialization dependency.
val testKotlinxVersion =
when (val selection = providers.gradleProperty("nav3TestKotlinx").getOrElse("floor")) {
"floor" -> kotlinxSerializationFloor
"latestStable" -> matrixLibs.versions.kotlinxSerialization.latestStable.get()
else -> error("nav3TestKotlinx must be floor or latestStable, but was $selection.")
}

dependencies {
implementation(projects.sentry)
compileOnly(libs.androidx.lifecycle.runtime.compose)

compileOnly(libs.androidx.compose.runtime)
compileOnly(libs.androidx.compose.ui)
compileOnly(libs.androidx.lifecycle.runtime.compose)
compileOnly(matrixLibs.kotlinxSerialization.core) {
version { strictly(kotlinxSerializationFloor) }
}

testImplementation(projects.sentryAndroidCore)
testImplementation(projects.sentryTestSupport)
Expand All @@ -91,6 +108,9 @@ dependencies {
testImplementation(libs.mockito.core)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.roboelectric)
testImplementation(matrixLibs.kotlinxSerialization.core) {
version { strictly(testKotlinxVersion) }
}
}

tasks.withType<Detekt>().configureEach {
Expand Down
26 changes: 26 additions & 0 deletions sentry-android-navigation3/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,29 @@
-keepattributes LineNumberTable,SourceFile

##---------------End: proguard configuration for Compose ----------

##---------------Begin: proguard configuration for kotlinx.serialization ----------

# The kotlinx.serialization compatibility probe looks up this SDK-owned fixture's serializer via reflection, as the built-in mappers look
# up those of apps' back stack entries. kotlinx.serialization's R8 rules before 1.8.0 keep an object's serializer() only while its INSTANCE
# field is kept, and R8 full mode removes INSTANCE here, as the SDK only refers to the object's class. The probe would then be inconclusive
# for object lookups.
-keepclassmembers class io.sentry.compose.navigation3.internal.backstack.kotlinx.KotlinxCompatibilityProbe$ProbeObject {
public static ** INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}

# Serial names survive R8 minification because Kotlin's serialization compiler plugin fixes them at compile time. Our built-in mapper
# fallback for private `@Serializable` objects relies on members preserved by kotlinx.serialization's own consumer rules.

# We don't ship rules for `@Serializable` classes with named companion objects. kotlinx.serialization's rules cover them but only from
# 1.10.0 on. A generic rule set that fixes older versions exists, but we don't apply it because it would keep `InnerClasses` and
# named-companion class names in every host app.

# We don't include a -dontwarn rule for kotlinx.serialization even though it's a compileOnly dependency. The only apps potentially affected
# are those that use sentry-android-navigation3 but not Nav3 (which brings in kotlinx-serialization-core via navigation3-runtime). Adding a
# broad `-dontwarn kotlinx.serialization.**` rule could suppress legitimate – and unrelated – R8 missing-class errors for apps that use
# Nav3, causing them to crash at runtime rather than fail at buildtime. Apps that need the -dontwarn rule (likely the null set) can add it
# themselves.

##---------------End: proguard configuration for kotlinx.serialization ----------
Loading
Loading