From 15c98b6467c3076496117af092c61af4b5e1831e Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Wed, 25 Nov 2026 16:19:29 +0100 Subject: [PATCH 1/3] ref(android): Narrow consumer keep rules to what the SDK reads Classes that are only checked by name now keep just their name, the NDK entry points keep only init() and close(), replay keeps the names of the three Painters isMaskable() leaves unmasked, LayoutNode keeps only the reflected members, and the Compose tag elements keep only their tag field. The app-wide Integration keepnames is dropped, since integration names are string literals now. Refs #6771 Refs JAVA-856 Co-Authored-By: Claude Opus 5.5 --- sentry-android-core/proguard-rules.pro | 10 +++------- sentry-android-fragment/proguard-rules.pro | 2 +- sentry-android-ndk-outproc/proguard-rules.pro | 5 ++++- sentry-android-ndk/proguard-rules.pro | 5 ++++- sentry-android-replay/proguard-rules.pro | 7 +++++-- sentry-android-timber/proguard-rules.pro | 2 +- sentry-compose/proguard-rules.pro | 8 ++++---- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/sentry-android-core/proguard-rules.pro b/sentry-android-core/proguard-rules.pro index 34fc51f709a..ec12186cd19 100644 --- a/sentry-android-core/proguard-rules.pro +++ b/sentry-android-core/proguard-rules.pro @@ -1,13 +1,12 @@ ##---------------Begin: proguard configuration for android-core ---------- ##---------------Begin: proguard configuration for androidx.core ---------- --keep class androidx.core.app.FrameMetricsAggregator { (...); } --keep interface androidx.core.view.ScrollingView { *; } +-keepnames class androidx.core.app.FrameMetricsAggregator +-keepnames interface androidx.core.view.ScrollingView ##---------------End: proguard configuration for androidx.core ---------- ##---------------Begin: proguard configuration for androidx.lifecycle ---------- --keep interface androidx.lifecycle.DefaultLifecycleObserver { *; } --keep class androidx.lifecycle.ProcessLifecycleOwner { (...); } +-keepnames class androidx.lifecycle.ProcessLifecycleOwner ##---------------End: proguard configuration for androidx.lifecycle ---------- # To mitigate the issue on R8 site (https://issuetracker.google.com/issues/235733922) @@ -45,9 +44,6 @@ # disagree. Unused Throwables may still be removed, and retained Throwables may still be obfuscated. -keep,allowshrinking,allowobfuscation class * extends java.lang.Throwable -# Keep Classnames for integrations --keepnames class * implements io.sentry.Integration - -dontwarn io.sentry.apollo.SentryApolloInterceptor -keepnames class io.sentry.apollo.SentryApolloInterceptor diff --git a/sentry-android-fragment/proguard-rules.pro b/sentry-android-fragment/proguard-rules.pro index 71e58d6e8aa..b60107a5e23 100644 --- a/sentry-android-fragment/proguard-rules.pro +++ b/sentry-android-fragment/proguard-rules.pro @@ -1,7 +1,7 @@ ##---------------Begin: proguard configuration for Fragment ---------- # The Android SDK checks at runtime if these classes are available via Class.forName --keep class io.sentry.android.fragment.FragmentLifecycleIntegration { (...); } +-keepnames class io.sentry.android.fragment.FragmentLifecycleIntegration -keepnames class androidx.fragment.app.FragmentManager$FragmentLifecycleCallbacks # To ensure that stack traces is unambiguous diff --git a/sentry-android-ndk-outproc/proguard-rules.pro b/sentry-android-ndk-outproc/proguard-rules.pro index 022d5bb3a1e..1ae8ad4972c 100644 --- a/sentry-android-ndk-outproc/proguard-rules.pro +++ b/sentry-android-ndk-outproc/proguard-rules.pro @@ -1,6 +1,9 @@ ##---------------Begin: proguard configuration for NDK outproc ---------- # The Android SDK checks at runtime if this class is available via Class.forName --keep class io.sentry.android.ndk.outproc.SentryNdkOutproc { *; } +-keep class io.sentry.android.ndk.outproc.SentryNdkOutproc { + public static void init(...); + public static void close(); +} ##---------------End: proguard configuration for NDK outproc ---------- diff --git a/sentry-android-ndk/proguard-rules.pro b/sentry-android-ndk/proguard-rules.pro index db825e27b4d..e80adfa4fa3 100644 --- a/sentry-android-ndk/proguard-rules.pro +++ b/sentry-android-ndk/proguard-rules.pro @@ -1,7 +1,10 @@ ##---------------Begin: proguard configuration for NDK ---------- # The Android SDK checks at runtime if this class is available via Class.forName --keep class io.sentry.android.ndk.SentryNdk { *; } +-keep class io.sentry.android.ndk.SentryNdk { + public static void init(...); + public static void close(); +} # The JNI layer uses this class through reflection -keep class io.sentry.protocol.DebugImage { *; } diff --git a/sentry-android-replay/proguard-rules.pro b/sentry-android-replay/proguard-rules.pro index 90a78965e89..6c20fc56940 100644 --- a/sentry-android-replay/proguard-rules.pro +++ b/sentry-android-replay/proguard-rules.pro @@ -4,7 +4,10 @@ # Rules to detect Images/Icons and mask them -dontwarn androidx.compose.ui.graphics.painter.Painter --keepnames class * extends androidx.compose.ui.graphics.painter.Painter +# isMaskable() leaves these Painters unmasked by name and masks every other one +-keepnames class androidx.compose.ui.graphics.vector.VectorPainter +-keepnames class androidx.compose.ui.graphics.painter.ColorPainter +-keepnames class androidx.compose.ui.graphics.painter.BrushPainter -keepclasseswithmembernames class * { androidx.compose.ui.graphics.painter.Painter painter; } @@ -32,7 +35,7 @@ -dontwarn androidx.camera.view.PreviewView -keepnames class androidx.camera.view.PreviewView # Rules to walk the Compose Node tree. --keep class androidx.compose.ui.node.LayoutNode { +-keepclassmembers class androidx.compose.ui.node.LayoutNode { *** getChildren*(...); *** getOuterCoordinator*(...); *** getCollapsedSemantics*(...); diff --git a/sentry-android-timber/proguard-rules.pro b/sentry-android-timber/proguard-rules.pro index 87f033ce584..7bd6693d6bd 100644 --- a/sentry-android-timber/proguard-rules.pro +++ b/sentry-android-timber/proguard-rules.pro @@ -1,7 +1,7 @@ ##---------------Begin: proguard configuration for Timber ---------- # The Android SDK checks at runtime if these classes are available via Class.forName --keep class io.sentry.android.timber.SentryTimberIntegration { (...); } +-keepnames class io.sentry.android.timber.SentryTimberIntegration -keepnames class timber.log.Timber # To ensure that stack traces is unambiguous diff --git a/sentry-compose/proguard-rules.pro b/sentry-compose/proguard-rules.pro index 30473497a5f..2b8a6ca82b0 100644 --- a/sentry-compose/proguard-rules.pro +++ b/sentry-compose/proguard-rules.pro @@ -1,8 +1,8 @@ ##---------------Begin: proguard configuration for Compose ---------- # The Android SDK checks at runtime if these classes are available via Class.forName --keep class io.sentry.compose.gestures.ComposeGestureTargetLocator { (...); } --keep class io.sentry.compose.viewhierarchy.ComposeViewHierarchyExporter { (...); } +-keepnames class io.sentry.compose.gestures.ComposeGestureTargetLocator +-keepnames class io.sentry.compose.viewhierarchy.ComposeViewHierarchyExporter -keepnames interface androidx.compose.ui.node.Owner -keepclassmembers class androidx.compose.ui.node.LayoutNode { @@ -14,8 +14,8 @@ -keepnames class androidx.compose.foundation.ScrollingLayoutElement -keepnames class androidx.compose.foundation.ScrollingContainerElement -keepnames class androidx.compose.foundation.ScrollableAreaElement --keepnames class androidx.compose.ui.platform.TestTagElement { *; } --keepnames class io.sentry.compose.SentryModifier$SentryTagModifierNodeElement { *; } +-keepnames class androidx.compose.ui.platform.TestTagElement { java.lang.String tag; } +-keepnames class io.sentry.compose.SentryModifier$SentryTagModifierNodeElement { java.lang.String tag; } # R8 will warn about missing classes if people don't have androidx.compose-navigation on their # classpath, but this is fine, these classes are used in an internal class which is only used when From ef9f369195b9a2e1c414e21c609881646fc27da3 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Wed, 25 Nov 2026 16:20:35 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 735831f2f98..f0109e2c162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ ## Unreleased +### Improvements + +- Android: Narrow consumer keep rules to the classes and members the SDK reads by reflection, so R8 can optimize more of your app ([#6779](https://github.com/getsentry/sentry-java/pull/6779)) + ### Fixes - Session Replay: Mask Compose images loaded with Coil 3.1+ `AsyncImage` when `maskAllImages` is enabled ([#6759](https://github.com/getsentry/sentry-java/pull/6759)) From d2420847bcb14922662858c367a085244a86cbcc Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 26 Nov 2026 16:02:41 +0100 Subject: [PATCH 3/3] fix(replay): Unmask Compose painters by type, not by class name isMaskable() left any Painter unmasked whose class name contained Vector, Color, or Brush. Once R8 renames an app's painter, that check gave different results in debug and release. Checking the three AndroidX types directly behaves the same in both, and drops their keep rules. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + sentry-android-replay/proguard-rules.pro | 7 +-- .../io/sentry/android/replay/util/Nodes.kt | 17 +++--- .../sentry/android/replay/util/NodesTest.kt | 57 +++++++++++++++++++ 4 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 sentry-android-replay/src/test/java/io/sentry/android/replay/util/NodesTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index f0109e2c162..39b0082699c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Fixes +- Session Replay: Mask Compose images the same way in debug and release builds. Only `VectorPainter`, `ColorPainter`, and `BrushPainter` are left unmasked, instead of any Painter whose class name contains `Vector`, `Color`, or `Brush` ([#6779](https://github.com/getsentry/sentry-java/pull/6779)) - Session Replay: Mask Compose images loaded with Coil 3.1+ `AsyncImage` when `maskAllImages` is enabled ([#6759](https://github.com/getsentry/sentry-java/pull/6759)) - Profiling: No longer crash on API 35+ devices whose framework can't load `ProfilingManager`. Perfetto profiling is turned off on those devices instead ([#6742](https://github.com/getsentry/sentry-java/pull/6742)) - Android: Out-of-process crash reporting now supports Android 5.0 (API level 21) and later, previously required Android 11 (API level 30) ([#6614](https://github.com/getsentry/sentry-java/pull/6614)) diff --git a/sentry-android-replay/proguard-rules.pro b/sentry-android-replay/proguard-rules.pro index 6c20fc56940..52f81053c34 100644 --- a/sentry-android-replay/proguard-rules.pro +++ b/sentry-android-replay/proguard-rules.pro @@ -4,10 +4,9 @@ # Rules to detect Images/Icons and mask them -dontwarn androidx.compose.ui.graphics.painter.Painter -# isMaskable() leaves these Painters unmasked by name and masks every other one --keepnames class androidx.compose.ui.graphics.vector.VectorPainter --keepnames class androidx.compose.ui.graphics.painter.ColorPainter --keepnames class androidx.compose.ui.graphics.painter.BrushPainter +-dontwarn androidx.compose.ui.graphics.painter.ColorPainter +-dontwarn androidx.compose.ui.graphics.painter.BrushPainter +-dontwarn androidx.compose.ui.graphics.vector.VectorPainter -keepclasseswithmembernames class * { androidx.compose.ui.graphics.painter.Painter painter; } diff --git a/sentry-android-replay/src/main/java/io/sentry/android/replay/util/Nodes.kt b/sentry-android-replay/src/main/java/io/sentry/android/replay/util/Nodes.kt index a32c51174a8..7146f20464c 100644 --- a/sentry-android-replay/src/main/java/io/sentry/android/replay/util/Nodes.kt +++ b/sentry-android-replay/src/main/java/io/sentry/android/replay/util/Nodes.kt @@ -28,7 +28,10 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Rect import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorProducer +import androidx.compose.ui.graphics.painter.BrushPainter +import androidx.compose.ui.graphics.painter.ColorPainter import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.graphics.vector.VectorPainter import androidx.compose.ui.layout.LayoutCoordinates import androidx.compose.ui.layout.findRootCoordinates import androidx.compose.ui.node.LayoutNode @@ -111,20 +114,14 @@ internal fun LayoutNode.isMaskableImage(): Boolean? { } /** - * We heuristically check the known classes that are coming from local assets usually: - * [androidx.compose.ui.graphics.vector.VectorPainter] - * [androidx.compose.ui.graphics.painter.ColorPainter] - * [androidx.compose.ui.graphics.painter.BrushPainter] + * Only [VectorPainter], [ColorPainter], and [BrushPainter] are left unmasked, because they draw + * local vectors and fills. Every other Painter may draw a remote image, so it is masked. * * In theory, [androidx.compose.ui.graphics.painter.BitmapPainter] can also come from local assets, * but it can as well come from a network resource, so we preemptively mask it. */ -internal fun Painter.isMaskable(): Boolean { - val className = this::class.java.name - return !className.contains("Vector") && - !className.contains("Color") && - !className.contains("Brush") -} +internal fun Painter.isMaskable(): Boolean = + this !is VectorPainter && this !is ColorPainter && this !is BrushPainter /** * This method is necessary to mask text in Compose. diff --git a/sentry-android-replay/src/test/java/io/sentry/android/replay/util/NodesTest.kt b/sentry-android-replay/src/test/java/io/sentry/android/replay/util/NodesTest.kt new file mode 100644 index 00000000000..946ce877a73 --- /dev/null +++ b/sentry-android-replay/src/test/java/io/sentry/android/replay/util/NodesTest.kt @@ -0,0 +1,57 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + +package io.sentry.android.replay.util + +import android.graphics.Bitmap +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.graphics.asImageBitmap +import androidx.compose.ui.graphics.drawscope.DrawScope +import androidx.compose.ui.graphics.painter.BitmapPainter +import androidx.compose.ui.graphics.painter.BrushPainter +import androidx.compose.ui.graphics.painter.ColorPainter +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.graphics.vector.VectorPainter +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.common.truth.Truth.assertThat +import kotlin.test.Test +import org.junit.runner.RunWith +import org.robolectric.annotation.Config + +@RunWith(AndroidJUnit4::class) +@Config(sdk = [35]) +class NodesTest { + + @Test + fun `VectorPainter is not maskable`() { + assertThat(VectorPainter().isMaskable()).isFalse() + } + + @Test + fun `ColorPainter is not maskable`() { + assertThat(ColorPainter(Color.Red).isMaskable()).isFalse() + } + + @Test + fun `BrushPainter is not maskable`() { + assertThat(BrushPainter(SolidColor(Color.Red)).isMaskable()).isFalse() + } + + @Test + fun `BitmapPainter is maskable`() { + val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888).asImageBitmap() + assertThat(BitmapPainter(bitmap).isMaskable()).isTrue() + } + + @Test + fun `a custom Painter is maskable even when its name contains Color, Vector, or Brush`() { + assertThat(ColorVectorBrushPainter().isMaskable()).isTrue() + } + + private class ColorVectorBrushPainter : Painter() { + override val intrinsicSize: Size = Size.Unspecified + + override fun DrawScope.onDraw() = Unit + } +}