Skip to content

fix(android): Generate modules.json into build folder instead of source tree - #6753

Open
antonis wants to merge 3 commits into
al/fix-gradle-sentry-options-generated-assetsfrom
al/fix-gradle-modules-generated-assets
Open

antonis wants to merge 3 commits into
al/fix-gradle-sentry-options-generated-assetsfrom
al/fix-gradle-modules-generated-assets

Conversation

@antonis

@antonis antonis commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Note

Stacked on #6751 (base branch al/fix-gradle-sentry-options-generated-assets). Please merge #6751 first; this PR's diff will collapse to modules-only once it does.

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

This replaces the Exec + Delete cleanup tasks with a typed CollectModulesTask that:

  • Writes into build/generated/sentry/modules/<variant>/ — never into src/main/assets.
  • Declares the source map, the collect-modules script, the module search paths, and the opt-out 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<Variant>Assets with correct ordering. A classic sourceSets["main"].assets.srcDir + scoped merge<Variant>Assets dependsOn fallback covers older AGP.
  • Runs the node collector through injected ExecOperations, so it stays Configuration Cache compatible.

💡 Motivation and Context

Follow-up to #6751. The Android Gradle plugin generated modules.json into the version-controlled android/app/src/main/assets directory on release builds (via an Exec task), then removed it afterward with a cleanup task. That Exec task declared no Gradle inputs/outputs, so it broke up-to-date checks and build caching for the asset-merge tasks, and a failed build could leave the file behind in the source tree — the same anti-pattern reported in #6750, of which sentry.options.json (#6751) was the first instance.

💚 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 12:30
…ce tree

The Android Gradle plugin collected `modules.json` into the version-controlled
`src/main/assets` directory on release builds via an `Exec` task with no declared
inputs/outputs, then removed it afterward with a cleanup task. That broke
up-to-date checks and build caching for asset merging, and a failed build could
leave the file behind in the source tree.

Replace it with a typed `CollectModulesTask` that writes into
`build/generated/sentry/modules/<variant>`, registered as a generated assets
source via the AGP Variant API (with a classic source-set fallback), so AGP
merges and orders it into `merge<Variant>Assets` with correct up-to-date/caching
behavior. Lint tasks depend on it explicitly (Gradle 9 rejects the previously
implicit dependency), and the source-map cleanup now runs after it.

Mirrors the `sentry.options.json` fix (#6751); closes the same anti-pattern for
`modules.json` from #6750.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@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 modules.json into build folder instead of source tree by antonis in #6753
  • 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.

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

@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
Comment thread packages/core/sentry.gradle.kts Outdated
@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 423.54 ms 428.93 ms 5.39 ms
Size 50.56 MiB 56.50 MiB 5.93 MiB

Baseline results on branch: al/fix-gradle-sentry-options-generated-assets

Startup times

Revision Plain With Sentry Diff
6dc72d4+dirty 468.91 ms 547.58 ms 78.67 ms

App size

Revision Plain With Sentry Diff
6dc72d4+dirty 50.56 MiB 56.49 MiB 5.93 MiB

…arn on stale copy

Addresses review feedback on the modules.json generated-assets change:

- Source-set fallback (old AGP < 7.3) now registers each variant's generated
  modules dir into that variant's own source set instead of the shared "main".
  Adding per-variant dirs to "main" leaked modules.json into debug and caused a
  duplicate-asset merge conflict between multiple non-debug variants. Because each
  variant is now isolated, no dedup guard is required (unlike the shared-dir
  options fallback). The primary AGP 7.3+ variant-API path was already scoped and
  is unchanged.
- Warn on a stale modules.json left in src/main/assets by older plugin versions
  (mirrors the sentry.options.json warning), since a leftover copy would clash
  with the generated one during asset merge on upgrade.

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

Copy link
Copy Markdown
Contributor

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 428.24 ms 459.82 ms 31.58 ms
Size 50.56 MiB 56.50 MiB 5.93 MiB

Baseline results on branch: al/fix-gradle-sentry-options-generated-assets

Startup times

Revision Plain With Sentry Diff
6dc72d4+dirty 471.48 ms 552.45 ms 80.97 ms

App size

Revision Plain With Sentry Diff
6dc72d4+dirty 50.56 MiB 56.49 MiB 5.93 MiB

@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 8208e15. Configure here.

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.

1 participant