Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RNGP - Add option to disable bundle compression (was: Make all React Native apps start 12% faster) #49449

Closed
wants to merge 13 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ abstract class ReactExtension @Inject constructor(val project: Project) {
val bundleAssetName: Property<String> =
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<Boolean> =
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ReactPlugin : Plugin<Project> {
}
configureAutolinking(project, extension)
configureCodegen(project, extension, rootExtension, isLibrary = false)
configureResources(project, extension)
}

// Library Only Configuration
Expand Down Expand Up @@ -110,6 +111,16 @@ class ReactPlugin : Plugin<Project> {
}
}

/** 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(
Expand Down
Loading