diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 6222bdb8684248..8fd0a54dbd3932 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -61,9 +61,16 @@ class ReactPlugin : Plugin { // This registers the $buildDir/generated/res/react/ folder as a // res folder to be consumed with the old AGP Apis which are not broken. project.extensions.getByType(AppExtension::class.java).apply { - this.applicationVariants.all { - it.registerGeneratedResFolders( - project.layout.buildDirectory.files("generated/res/react/${it.name}")) + this.applicationVariants.all { variant -> + val isDebuggableVariant = + extension.debuggableVariants.get().any { it.equals(variant.name, ignoreCase = true) } + val targetName = variant.name.replaceFirstChar { it.uppercase() } + val bundleTaskName = "createBundle${targetName}JsAndAssets" + if (!isDebuggableVariant) { + variant.registerGeneratedResFolders( + project.layout.buildDirectory.files("generated/res/react/${variant.name}")) + variant.mergeResourcesProvider.get().dependsOn(bundleTaskName) + } } } configureCodegen(project, extension, isLibrary = false)