Skip to content

fix(cli): Send the Android wizard's test error once, in debuggable builds - #2803

Merged
antonis merged 2 commits into
mainfrom
fix/android-wizard-test-error-once
Dec 2, 2026
Merged

antonis merged 2 commits into
mainfrom
fix/android-wizard-test-error-once

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

This comes from testing sentry wizard android on fresh Android Studio projects (getsentry/sentry-java#6797).

The wizard adds a test error to the main Activity's onCreate through an OnGlobalLayoutListener that 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):

  • The Java and Kotlin snippets use an anonymous ViewTreeObserver.OnGlobalLayoutListener that calls removeOnGlobalLayoutListener(this) first in onGlobalLayout(). It still waits for the first layout, so the error's screenshot shows the UI. It removes itself through contentView.getViewTreeObserver() rather than a saved observer, because the observer you get in onCreate, before the view is attached, is merged into the window's observer later, and removing from the old one would throw.
  • The snippet runs only when ApplicationInfo.FLAG_DEBUGGABLE is set. It doesn't use BuildConfig.DEBUG, because AGP 8 and later don't generate BuildConfig unless buildFeatures.buildConfig is on.
  • android.content.pm.ApplicationInfo and android.view.ViewTreeObserver are fully qualified, like android.R.id.content, so the wizard still adds only the io.sentry.Sentry import.
  • The comment now says what the snippet does and to remove it after confirming the integration works.
  • The snippet indents each nesting level by 4 spaces, matching Android Studio's default for Java and Kotlin and the 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 with onCreate's body.

code-tools.ts is unchanged and still inserts the snippet right after super.onCreate(...).

@sentry/wizard has the same snippet and needs the same fix.

via Antonis Lilis.

--

View Session [Sentry]

…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>
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Dec 2, 2026 3:53pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Dec 2, 2026 3:53pm UTC

Request Review

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>
@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 2, 2026 15:53 Inactive
@antonis
antonis marked this pull request as ready for review December 2, 2026 16:15
@antonis
antonis added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit c1b346a Dec 2, 2026
32 checks passed
@antonis
antonis deleted the fix/android-wizard-test-error-once branch December 2, 2026 16:22

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — a84f5c86 Deployed Dec 2, 2026 by vercel[bot]
Preview – sentry-local — a84f5c86 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant