ref(snapshot): Use AGP addGeneratedSourceDirectory API#1117
ref(snapshot): Use AGP addGeneratedSourceDirectory API#1117runningcode merged 8 commits intomainfrom
Conversation
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>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
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>
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>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>


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
addGeneratedSourceDirectoryAPIsources.javainstead ofsources.kotlinto work around AGP buggenerateSentrySnapshotTests{Variant}) with per-variant output directories to avoid overlapping outputs and build cache corruption#skip-changelog