Skip to content

ref(snapshot): Use AGP addGeneratedSourceDirectory API#1117

Merged
runningcode merged 8 commits intomainfrom
no/snapshot-use-agp-source-api
Mar 24, 2026
Merged

ref(snapshot): Use AGP addGeneratedSourceDirectory API#1117
runningcode merged 8 commits intomainfrom
no/snapshot-use-agp-source-api

Conversation

@runningcode
Copy link
Copy Markdown
Contributor

@runningcode runningcode commented Mar 24, 2026

The old wiring up of tasks was a bit hacky and was causing problems in consuming apps I was testing. This should fix the dependency issues.

Summary

  • Replace manual source set wiring and regex-based task dependency matching with AGP's addGeneratedSourceDirectory API
  • Use sources.java instead of sources.kotlin to work around AGP bug
  • Register a per-variant task (generateSentrySnapshotTests{Variant}) with per-variant output directories to avoid overlapping outputs and build cache corruption

#skip-changelog

Replace manual source set wiring and regex-based task dependency
matching with the proper AGP `addGeneratedSourceDirectory` API.
This lets AGP handle the source directory registration and task
dependency setup automatically per variant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

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


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

// for the Kotlin compiler to pick up the generated sources.
android.sourceSets.getByName("test").kotlin.srcDir(generateTask.flatMap { it.outputDir })
val androidComponents =
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Plugin breaks on library modules using ApplicationAndroidComponentsExtension

High Severity

ApplicationAndroidComponentsExtension is only registered for com.android.application modules. Paparazzi is most commonly applied to com.android.library modules, where this getByType call will throw an UnknownDomainObjectException at configuration time. The old code used BaseExtension, which works for both application and library modules. A more general type like AndroidComponentsExtension would preserve the original compatibility.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a good point, but in this first version we only support application modules.

The previous approach used a single task and `sources.kotlin` which is
broken in AGP (https://issuetracker.google.com/issues/268248348).
Switch to `sources.java` and register a per-variant task so each
variant's unit test compilation gets its own generated source directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

runningcode and others added 2 commits March 24, 2026 11:40
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Each variant's task was writing to the same output path, causing
overlapping-output errors and build cache corruption.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
runningcode and others added 2 commits March 24, 2026 14:01
AGP 9.0 deprecated `variant.unitTest` in favor of `variant.hostTests`.
Use the new API when running on AGP 9.0+ while keeping the old path
for older versions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
runningcode and others added 2 commits March 24, 2026 14:12
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@runningcode runningcode merged commit cfa9388 into main Mar 24, 2026
22 of 23 checks passed
@runningcode runningcode deleted the no/snapshot-use-agp-source-api branch March 24, 2026 16:32
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.

2 participants