Skip to content

Commit 0930fb9

Browse files
antonisclaude
andcommitted
fix(android): fix variant capitalization and task timing in sentry.gradle
- Replace v.name.capitalize() with substring(0,1).toUpperCase()+substring(1) so that flavored variants like freeRelease produce FreeRelease (not Freerelease), matching React Native's bundle task naming convention. - Replace tasks.named() with tasks.configureEach + name-set filter to handle bundle tasks registered after sentry's onVariants callback fires (e.g. when sentry.gradle is applied before the React Native plugin). configureEach does not iterate or realize the task container so the Fullstory AGP Artifacts API fix (#5698) and react-native-legal fix (#5236) are preserved. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 05a6b03 commit 0930fb9

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

packages/core/sentry.gradle

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,18 @@ 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 and use tasks.named() to target them
72-
// lazily — avoiding eager task realization that breaks AGP Artifacts API (e.g. Fullstory)
73-
// and react-native-legal's lazily-registered tasks (issue #5236).
74-
def variantCapitalized = v.name.capitalize()
75-
def sentryBundleTaskName = ["createBundle${variantCapitalized}JsAndAssets", "bundle${variantCapitalized}JsAndAssets"].find { tasks.names.contains(it) }
76-
if (sentryBundleTaskName == null) {
77-
project.logger.warn(
78-
"[sentry] No React Native bundle task found for variant '${v.name}'. " +
79-
"Expected 'createBundle${variantCapitalized}JsAndAssets' or " +
80-
"'bundle${variantCapitalized}JsAndAssets' — neither is registered. " +
81-
"Source maps will NOT be uploaded for this variant.")
82-
return
83-
}
84-
85-
tasks.named(sentryBundleTaskName).configure { bundleTask ->
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).
76+
//
77+
// Capitalization: only the first character is upper-cased so that flavored variants
78+
// like "freeRelease" become "FreeRelease" (not "Freerelease" from Groovy capitalize()).
79+
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
8683
if (!bundleTask.enabled) return
8784
def shouldCleanUp
8885
def sourcemapOutput

0 commit comments

Comments
 (0)