From 489379f97ff714e2a2be0a1c7ca6438f72c764d9 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Wed, 18 Jan 2023 04:25:14 -0800 Subject: [PATCH] Fix for resources not correctly bundlded on release appbundles Summary: When downgrading from AGP 7.4 to 7.3 we were forced to resort to older APIs to bundle resources. It seems like we haven't properly wired the task to make sure resources generated by Metro are correctly accounted before the generation of release app bundles/apks. This fixes it. This fix can also be removed once we are on AGP 7.4 Fixes #35865 Changelog: [Android] [Fixed] - Fix for resources not correctly bundlded on release appbundles Differential Revision: D42573450 fbshipit-source-id: f3f3ed228788e9c406e066b63e70f20fd0f4daeb --- .../main/kotlin/com/facebook/react/ReactPlugin.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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)