From 85c000e81eead710a1b7b13cc2a1cbeb4d24bfb4 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 f058197818b..7d99b5c67fd 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 - # SentryClient logs the processor's class name when it throws -keepnames class io.sentry.android.core.ScreenshotEventProcessor -keepnames class io.sentry.android.core.ViewHierarchyEventProcessor 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 5d20c64a20b..7937ce0eb6b 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(); +} # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native -keepclasseswithmembernames,includedescriptorclasses class io.sentry.** { diff --git a/sentry-android-replay/proguard-rules.pro b/sentry-android-replay/proguard-rules.pro index 1e7b08908d3..4bd803e7c62 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; } @@ -30,7 +33,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 4c847b6a053..a7b5558cd9c 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 @@ -11,8 +11,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 94cfb9e007e52562468bc677146cabae05b02f94 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f7e4b27a5..749f9336474 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Improvements - Android: Remove consumer keep rules that had no effect, so R8 can optimize more of your app ([#6778](https://github.com/getsentry/sentry-java/pull/6778)) +- 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 From 9fb60b329415880563618e43c5999c655661a5ac 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 749f9336474..9dab10330e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,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)) - Android: A crash long after `Sentry.init` is no longer marked as a startup crash when the device slept in between, because the time since init now counts deep sleep ([#6738](https://github.com/getsentry/sentry-java/pull/6738)) - Session Replay: Replays recovered after a crash no longer list `"null"` as a screen name when the last named frame leaves the buffer ([#6827](https://github.com/getsentry/sentry-java/pull/6827)) diff --git a/sentry-android-replay/proguard-rules.pro b/sentry-android-replay/proguard-rules.pro index 4bd803e7c62..eafa7d820c2 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 + } +}