Repository navigation
fix(cli): Send the Android wizard's test error once, in debuggable builds - #2803
Merged
Merged
Conversation
…ilds `sentry wizard android` added a test error to the main Activity's `onCreate` through an `OnGlobalLayoutListener` that it never removed. A global layout listener fires on every layout pass (rotation, the keyboard, insets, any view change), so the app kept sending test errors, in Release builds too if the snippet shipped. The Java and Kotlin snippets now use an anonymous listener that removes itself first in `onGlobalLayout()`, and run only when the app's `ApplicationInfo.FLAG_DEBUGGABLE` flag is set. They don't use `BuildConfig.DEBUG`, which AGP 8 and later don't generate by default. Class names stay fully qualified, so no imports are added. Refs getsentry/sentry-java#6797 Co-Authored-By: Antonis Lilis <antonis.lilis@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
The snippet started at 4 spaces but nested by 2. It now indents each
level by 4, matching Android Studio's default for Java and Kotlin and the
`sentry {}` block the wizard already writes. The first line stays at 4
spaces, in line with `onCreate`'s body.
Co-Authored-By: Antonis Lilis <antonis.lilis@sentry.io>
antonis
marked this pull request as ready for review
December 2, 2026 16:15
antonis
approved these changes
Dec 2, 2026
5 tasks
14 of 16 tasks
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This comes from testing
sentry wizard androidon fresh Android Studio projects (getsentry/sentry-java#6797).The wizard adds a test error to the main Activity's
onCreatethrough anOnGlobalLayoutListenerthat it never removes. A global layout listener fires on every layout pass, not just the first: rotation, the keyboard, insets, any view change. So the app sends a stream of test errors, and keeps doing it in Release builds if the snippet ships.The test error is now sent once per Activity creation, in debuggable builds only, like the iOS wizard's
#if DEBUG(#2798):ViewTreeObserver.OnGlobalLayoutListenerthat callsremoveOnGlobalLayoutListener(this)first inonGlobalLayout(). It still waits for the first layout, so the error's screenshot shows the UI. It removes itself throughcontentView.getViewTreeObserver()rather than a saved observer, because the observer you get inonCreate, before the view is attached, is merged into the window's observer later, and removing from the old one would throw.ApplicationInfo.FLAG_DEBUGGABLEis set. It doesn't useBuildConfig.DEBUG, because AGP 8 and later don't generateBuildConfigunlessbuildFeatures.buildConfigis on.android.content.pm.ApplicationInfoandandroid.view.ViewTreeObserverare fully qualified, likeandroid.R.id.content, so the wizard still adds only theio.sentry.Sentryimport.sentry {}block the wizard already writes. It used to start at 4 spaces but nest by 2. The first line stays at 4 spaces, in line withonCreate's body.code-tools.tsis unchanged and still inserts the snippet right aftersuper.onCreate(...).@sentry/wizardhas the same snippet and needs the same fix.via Antonis Lilis.
--
View Session [Sentry]