diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt index b67e8826b339f5..ba5ffca34b970a 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt @@ -76,6 +76,16 @@ abstract class ReactExtension @Inject constructor(val project: Project) { val bundleAssetName: Property = objects.property(String::class.java).convention("index.android.bundle") + /** + * Whether the Bundle Asset should be compressed when packaged into a `.apk`, or not. + * Disabling compression for the `.bundle` allows it to be directly memory-mapped to RAM, + * hence improving startup time - at the cost of a larger resulting `.apk` size. + * + * Default: false + */ + val enableBundleCompression: Property = + objects.property(Boolean::class.java).convention(false) + /** * Toggles the .so Cleanup step. If enabled, we will clean up all the unnecessary files before the * bundle task. If disabled, the developers will have to manually cleanup the files. Default: true diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 9cf504539e2e4d..ffcf76ad163d09 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -81,6 +81,7 @@ class ReactPlugin : Plugin { } configureAutolinking(project, extension) configureCodegen(project, extension, rootExtension, isLibrary = false) + configureResources(project, extension) } // Library Only Configuration @@ -110,6 +111,16 @@ class ReactPlugin : Plugin { } } + /** This function configures Android resources - in this case just the bundle */ + private fun configureResources(project: Project, reactExtension: ReactExtension) { + project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext -> + val bundleFileExtension = reactExtension.bundleAssetName.get().substringAfterLast('.', "") + if (!reactExtension.enableBundleCompression.get() && bundleFileExtension.isNotBlank()) { + ext.androidResources.noCompress.add(bundleFileExtension) + } + } + } + /** This function sets up `react-native-codegen` in our Gradle plugin. */ @Suppress("UnstableApiUsage") private fun configureCodegen(