An oversized mobile application leads to higher user abandonment rates. If your React Native app downloads are exceeding 100MB, users on mobile networks will cancel. Here is how to shrink your React Native bundles through Hermes optimization, asset compression, and Proguard compilation.
1. Enable Hermes and Proguard
Hermes is an open-source JavaScript engine optimized for running React Native on mobile. It compiles JavaScript into bytecode ahead of time, speeding up startup times and reducing binary sizes.
To configure Hermes and code minification in Android, edit your android/app/build.gradle file:
project.ext.react = [
enableHermes: true, // Compile JS to Hermes Bytecode
minifyEnabled: true, // Compress native code via Proguard
]
android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
2. Dynamic Asset Optimization
Do not bundle raw high-resolution images in the app binary. Instead:
- WebP Format: Convert PNG/JPG files to WebP. You can reduce file sizes by up to 75% with zero visible loss in quality.
- On-Demand Loading: Fetch heavy graphic assets dynamically from a CDN rather than embedding them in the binary.
- Vector Drawables: Use SVGs instead of raster files where possible.
3. ABI Splits for Android APKs
By default, an Android compilation builds a universal APK containing native code for all CPU architectures (arm64-v8a, armeabi-v7a, x86_64). You can configure Gradle to output split APKs for each architecture, reducing the download size for end-users:
android {
splits {
abi {
enable true
reset()
include "armeabi-v7a", "arm64-v8a", "x86_64"
universalApk false
}
}
}
4. Bundle Shrinkage Benchmarks
| Optimization Stage | iOS IPA Size | Android APK Size | Startup Delay |
|---|---|---|---|
| Raw Build (Default configurations) | 64MB | 32MB | 4.8s |
| Hermes + Proguard Enabled | 28MB | 14MB | 1.8s |
| WebP Asset Trimming + ABI Splits | 14MB | 6.2MB | 1.1s |
Optimizing bundles also speeds up compilation since there are fewer resources to package. To run builds on optimized hardware, check out M4 Apple Silicon runner speeds.
References & Citations
- Hermes Engine Benchmarks: Facebook Github Hermes
- Proguard Code Optimization: Guardsquare Support
- Expo prebuild benefits: Expo Prebuild Workflow