Skip to content

Commit 34b4c82

Browse files
antonisclaude
andcommitted
fix(android): move bundle task lookup to afterEvaluate, restore warning
Follow the SAGP pattern (sentry-android-gradle-plugin/util/tasks.kt): register project.afterEvaluate{} inside onVariants{} so that task lookup is deferred until after all plugins have registered their tasks. onVariants fires during project evaluation — before the task container is complete — so tasks.configureEach registered there could miss late-registered bundle tasks. afterEvaluate runs after all onVariants callbacks (including the React Native plugin's) have completed, making tasks.names reliable. Replaces tasks.configureEach + gradle.taskGraph.whenReady with: - project.afterEvaluate for timing - tasks.names.contains() guard with inline warn() for missing tasks - tasks.named() for a targeted lazy reference (no container iteration) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 469101e commit 34b4c82

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

packages/core/sentry.gradle

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,26 @@ plugins.withId('com.android.application') {
6868
androidComponents.onVariants(androidComponents.selector().all()) { v ->
6969
if (!v.name.toLowerCase().contains("debug")) {
7070
// Hook into the bundle task of react native to inject sourcemap generation parameters.
71-
// We predict bundle task names from the variant name and use tasks.configureEach() to
72-
// wire them lazily — avoiding eager task realization that breaks the AGP Artifacts API
73-
// (e.g. Fullstory, issue #5698) and react-native-legal's lazily-registered tasks
74-
// (issue #5236). configureEach also handles bundle tasks registered after this
75-
// onVariants callback fires (e.g. when sentry.gradle is applied before the RN plugin).
71+
// Defer task lookup to afterEvaluate so all plugins (including the React Native plugin)
72+
// have registered their tasks — onVariants fires during project evaluation, before the
73+
// task container is complete. tasks.named() is used for a targeted lazy reference that
74+
// does not iterate the container and avoids realizing unrelated tasks (fixes Fullstory
75+
// AGP Artifacts API conflict, issue #5698, and react-native-legal, issue #5236).
7676
//
7777
// Capitalization: only the first character is upper-cased so that flavored variants
7878
// like "freeRelease" become "FreeRelease" (not "Freerelease" from Groovy capitalize()).
7979
def variantCapitalized = v.name.substring(0, 1).toUpperCase() + v.name.substring(1)
80-
def bundleTaskNames = ["createBundle${variantCapitalized}JsAndAssets", "bundle${variantCapitalized}JsAndAssets"] as Set
81-
tasks.configureEach { bundleTask ->
82-
if (!bundleTaskNames.contains(bundleTask.name)) return
80+
project.afterEvaluate {
81+
def sentryBundleTaskName = ["createBundle${variantCapitalized}JsAndAssets", "bundle${variantCapitalized}JsAndAssets"].find { tasks.names.contains(it) }
82+
if (sentryBundleTaskName == null) {
83+
project.logger.warn(
84+
"[sentry] No React Native bundle task found for variant '${v.name}'. " +
85+
"Expected 'createBundle${variantCapitalized}JsAndAssets' or " +
86+
"'bundle${variantCapitalized}JsAndAssets' — neither is registered. " +
87+
"Source maps will NOT be uploaded for this variant.")
88+
return
89+
}
90+
tasks.named(sentryBundleTaskName).configure { bundleTask ->
8391
if (!bundleTask.enabled) return
8492
def shouldCleanUp
8593
def sourcemapOutput
@@ -320,18 +328,6 @@ plugins.withId('com.android.application') {
320328
packageTask.finalizedBy modulesCleanUpTask
321329
}
322330
}
323-
324-
// Warn if neither expected bundle task was registered by the time the task
325-
// graph is resolved — by then all plugins' onVariants callbacks (including
326-
// the React Native plugin's) have run, so tasks.names is complete.
327-
gradle.taskGraph.whenReady {
328-
if (bundleTaskNames.every { !tasks.names.contains(it) }) {
329-
project.logger.warn(
330-
"[sentry] No React Native bundle task found for variant '${v.name}'. " +
331-
"Expected 'createBundle${variantCapitalized}JsAndAssets' or " +
332-
"'bundle${variantCapitalized}JsAndAssets' — neither is registered. " +
333-
"Source maps will NOT be uploaded for this variant.")
334-
}
335331
}
336332
}
337333
}

0 commit comments

Comments
 (0)