Skip to content

Commit 5b6b7c0

Browse files
antonisclaude
andcommitted
fix(android): remove afterEvaluate wrapper, fix indentation in sentry.gradle
project.afterEvaluate{} is not needed: bundle tasks are already registered by the time onVariants fires, matching the timing of the original tasks.findAll. Moving the tasks.names.contains() check and tasks.named().configure{} directly into onVariants keeps the fix simple and avoids the regression risk that afterEvaluate introduced in the earlier PR #5690. Also fixes the indentation of the ~240-line configure{} closure body so it is visually distinct from the enclosing onVariants block. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6e0c31b commit 5b6b7c0

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

packages/core/sentry.gradle

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,11 @@ 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-
// 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).
71+
// tasks.names.contains() checks task existence without iterating or realizing the
72+
// container. tasks.named() provides a targeted lazy reference to the specific task,
73+
// avoiding the eager realization that tasks.findAll caused (fixes Fullstory AGP
74+
// Artifacts API conflict, issue #5698, and react-native-legal, issue #5236).
7675
//
77-
// Capitalization: only the first character is upper-cased so that flavored variants
78-
// like "freeRelease" become "FreeRelease" (not "Freerelease" from Groovy capitalize()).
7976
// All AGP Variant API accesses (outputs, applicationId, versionCode/Name providers)
8077
// must happen here inside onVariants — the variant object is not valid after this
8178
// callback returns.
@@ -85,17 +82,16 @@ plugins.withId('com.android.application') {
8582
def variantOutputsData = v.outputs.collect { output ->
8683
[baseName: output.baseName, versionCode: output.versionCode.getOrElse(0), versionName: output.versionName.getOrElse('')]
8784
}
88-
project.afterEvaluate {
89-
def sentryBundleTaskName = ["createBundle${variantCapitalized}JsAndAssets", "bundle${variantCapitalized}JsAndAssets"].find { tasks.names.contains(it) }
90-
if (sentryBundleTaskName == null) {
91-
project.logger.warn(
92-
"[sentry] No React Native bundle task found for variant '${variantName}'. " +
93-
"Expected 'createBundle${variantCapitalized}JsAndAssets' or " +
94-
"'bundle${variantCapitalized}JsAndAssets' — neither is registered. " +
95-
"Source maps will NOT be uploaded for this variant.")
96-
return
97-
}
98-
tasks.named(sentryBundleTaskName).configure { bundleTask ->
85+
def sentryBundleTaskName = ["createBundle${variantCapitalized}JsAndAssets", "bundle${variantCapitalized}JsAndAssets"].find { tasks.names.contains(it) }
86+
if (sentryBundleTaskName == null) {
87+
project.logger.warn(
88+
"[sentry] No React Native bundle task found for variant '${variantName}'. " +
89+
"Expected 'createBundle${variantCapitalized}JsAndAssets' or " +
90+
"'bundle${variantCapitalized}JsAndAssets' — neither is registered. " +
91+
"Source maps will NOT be uploaded for this variant.")
92+
return
93+
}
94+
tasks.named(sentryBundleTaskName).configure { bundleTask ->
9995
if (!bundleTask.enabled) return
10096
def shouldCleanUp
10197
def sourcemapOutput
@@ -336,7 +332,6 @@ plugins.withId('com.android.application') {
336332
packageTask.finalizedBy modulesCleanUpTask
337333
}
338334
}
339-
}
340335
}
341336
}
342337
}

0 commit comments

Comments
 (0)