Skip to content

fix(android): Generate sentry.options.json into build folder instead of source tree - #6751

Open
antonis wants to merge 4 commits into
mainfrom
al/fix-gradle-sentry-options-generated-assets
Open

antonis wants to merge 4 commits into
mainfrom
al/fix-gradle-sentry-options-generated-assets

Conversation

@antonis

@antonis antonis commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

This PR replaces the copy + cleanup tasks with a typed generateSentryOptions task that:

  • Writes into build/generated/sentry/options/ — never into src/main/assets.
  • Declares the source file and the SENTRY_ENVIRONMENT / SENTRY_RELEASE / SENTRY_DIST overrides as task inputs and the output dir as an output, so it participates correctly in up-to-date checks and the build cache.
  • Is registered as a generated assets source via the AGP Variant API (variant.sources.assets.addGeneratedSourceDirectory, reached reflectively since a script plugin can't depend on AGP types), so AGP wires it into merge*Assets with correct ordering. A classic sourceSets["main"].assets.srcDir + merge*Assets dependsOn fallback covers older AGP.
  • Stays Configuration Cache compatible (the action reads only captured inputs and does plain file I/O; onlyIf references only the task).

💡 Motivation and Context

Fixes #6750.

💚 How did you test it?

Manually, on samples/react-native (AGP 9.x / Gradle 9.4.1, JDK 17), since there is no Gradle test harness for the script plugin:

📝 Checklist

🔮 Next steps

antonis and others added 2 commits September 18, 2026 09:36
…of source tree

The Android Gradle plugin copied `sentry.options.json` into the version-controlled
`src/main/assets` during builds via a task with no declared inputs/outputs. That broke
Gradle's up-to-date checks and build caching for the asset-merge tasks and required a
cleanup task to remove the file afterward, which could leave the file behind on a failed
build.

Replace it with a typed `generateSentryOptions` task that writes into
`build/generated/sentry/options` with declared inputs/outputs (source file plus the
SENTRY_ENVIRONMENT/RELEASE/DIST overrides), registered as a generated assets source via
the AGP Variant API, with a classic sourceSets fallback for older AGP. Nothing is written
into the source tree anymore, and asset merging is now correctly cached.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@antonis antonis added the ready-to-merge Triggers the full CI test suite label Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(android): Generate sentry.options.json into build folder instead of source tree by antonis in #6751
  • fix(core): Declare optional peer dependencies to resolve phantom imports under strict package managers by antonis in #6729
  • Add missing exports and update public API report by antonis in #6731
  • test(ios): Reenable Session Replay E2E test by antonis in #6737
  • fix(ios): Honor shutdownTimeout on iOS by antonis in #6749

🤖 This preview updates automatically when you update the PR.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/core/sentry.gradle.kts Outdated
@antonis antonis added ready-to-merge Triggers the full CI test suite and removed ready-to-merge Triggers the full CI test suite labels Sep 18, 2026
Comment thread packages/core/sentry.gradle.kts
Comment thread packages/core/sentry.gradle.kts
@sentry

sentry Bot commented Sep 18, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Sentry RN io.sentry.reactnative.sample 8.27.0 (107) Release

⚙️ sentry-react-native Build Distribution Settings

@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 468.91 ms 547.58 ms 78.67 ms
Size 50.56 MiB 56.49 MiB 5.93 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
37a2091+dirty 407.82 ms 441.22 ms 33.40 ms
f3215d3+dirty 411.11 ms 454.38 ms 43.27 ms
bc8f61e+dirty 442.98 ms 506.56 ms 63.58 ms
f9c1ed4+dirty 431.00 ms 466.22 ms 35.22 ms
7887847+dirty 416.61 ms 462.04 ms 45.43 ms
57e0069+dirty 413.82 ms 453.47 ms 39.65 ms
a0a3177+dirty 441.27 ms 499.86 ms 58.59 ms
09a902f+dirty 427.38 ms 473.80 ms 46.42 ms
a5d243c+dirty 424.52 ms 485.18 ms 60.66 ms
5a23c47+dirty 423.85 ms 466.47 ms 42.62 ms

App size

Revision Plain With Sentry Diff
37a2091+dirty 48.30 MiB 53.58 MiB 5.28 MiB
f3215d3+dirty 48.30 MiB 53.49 MiB 5.19 MiB
bc8f61e+dirty 49.74 MiB 55.09 MiB 5.35 MiB
f9c1ed4+dirty 49.74 MiB 54.86 MiB 5.12 MiB
7887847+dirty 49.74 MiB 54.81 MiB 5.07 MiB
57e0069+dirty 49.74 MiB 54.85 MiB 5.11 MiB
a0a3177+dirty 49.74 MiB 55.37 MiB 5.63 MiB
09a902f+dirty 49.74 MiB 54.81 MiB 5.07 MiB
a5d243c+dirty 48.30 MiB 53.54 MiB 5.23 MiB
5a23c47+dirty 49.74 MiB 54.82 MiB 5.07 MiB

@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 471.48 ms 552.45 ms 80.97 ms
Size 50.56 MiB 56.49 MiB 5.93 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
f3215d3+dirty 396.53 ms 436.66 ms 40.13 ms
d0e3b3e+dirty 443.19 ms 480.00 ms 36.81 ms
a5d243c+dirty 499.20 ms 525.62 ms 26.42 ms
7fd0012+dirty 422.41 ms 445.57 ms 23.17 ms
0a147b2+dirty 442.80 ms 522.24 ms 79.44 ms
d7d54c6+dirty 423.54 ms 498.56 ms 75.02 ms
c823bb5+dirty 468.26 ms 516.16 ms 47.90 ms
5789645+dirty 502.66 ms 594.19 ms 91.53 ms
40c9884+dirty 453.76 ms 478.98 ms 25.22 ms
d771cd5+dirty 432.29 ms 464.38 ms 32.09 ms

App size

Revision Plain With Sentry Diff
f3215d3+dirty 48.30 MiB 53.49 MiB 5.19 MiB
d0e3b3e+dirty 49.74 MiB 55.09 MiB 5.34 MiB
a5d243c+dirty 48.30 MiB 53.54 MiB 5.23 MiB
7fd0012+dirty 50.56 MiB 56.46 MiB 5.90 MiB
0a147b2+dirty 49.74 MiB 55.08 MiB 5.34 MiB
d7d54c6+dirty 49.74 MiB 55.09 MiB 5.34 MiB
c823bb5+dirty 48.30 MiB 53.58 MiB 5.28 MiB
5789645+dirty 49.74 MiB 54.85 MiB 5.11 MiB
40c9884+dirty 49.74 MiB 55.09 MiB 5.34 MiB
d771cd5+dirty 49.74 MiB 55.36 MiB 5.62 MiB

…out output

The lint model/analysis tasks read the generated assets dir without a declared
dependency on generateSentryOptions, which Gradle 9 fails as an implicit
dependency error. Declare it explicitly.

Also make the SENTRY_COPY_OPTIONS_FILE opt-out an @input instead of onlyIf, so
disabling it re-runs the task and clears the output dir rather than leaving a
stale generated file to be packaged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e855733. Configure here.

Older plugin versions copied the file into src/main/assets; a crashed build
could leave it behind, where it now shadows or conflicts with the generated
copy. Emit a configuration-time warning pointing the user to remove it. Never
delete it automatically — the file may be intentional.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread packages/core/sentry.gradle.kts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sentry.gradle.kts unconditionally copies assets to the src/assets/main directory which breaks caching and up-to-date checks

1 participant