App Size Optimization - React Native
This guide helps you reduce your app's size on every device. By following these best practices, you can reduce load times and storage requirements while keeping the features your app needs.
Deliver Leaner Apps with App Bundles
Use Android App Bundles (AAB) to cut the download size of your app. App Bundles allow Google Play to dynamically generate APKs tailored to each device, so users only download the resources and code relevant to their specific configuration.
Recommended Practices:
-
Enable App Bundles: Configure your build to use the App Bundle format instead of APKs. This will allow Google Play to optimize your app for each device type automatically. -
Organize Resources by Device Type: Ensure that resources (like images and layouts) are organized by device type (such as screen density or language) to maximize the benefits of App Bundles. -
Test Modularization: If your app contains large, optional features, use dynamic feature modules to let users download them on demand. This reduces the initial download size and provides features only as needed. -
Monitor Size Reductions: Regularly analyze your app size to see where the most savings occur, and make sure that App Bundle optimizations are effectively reducing your app size across different device configurations.
Optimize Libraries for a Leaner App Experience
Managing dependencies carefully is essential for minimizing app size and improving performance. Every library or dependency included in your app adds to its overall size, so it’s crucial to only incorporate what’s necessary. Optimizing dependencies helps streamline your app, reduce load times, and enhance maintainability.
Recommended Practices:
-
Use Only Essential Libraries: Review all libraries and dependencies, removing any that are not critical to your app’s functionality. This helps avoid unnecessary bloat. -
Use Lightweight Alternatives: Whenever possible, choose lightweight libraries or modularized versions of larger ones. For example, opt for a specific feature module rather than including an entire library. -
Monitor Library Updates: Regularly update your dependencies to take advantage of any optimizations or size reductions made by the library maintainers. -
Minimize Native Libraries: If your app uses native libraries, ensure they’re essential and compatible across platforms, as they can significantly increase app size. -
Analyze Dependency Tree: Use tools like Gradle’s dependency analyzer to identify unnecessary or redundant dependencies, ensuring your app’s dependency tree is as lean as possible.
Optimize with ProGuard
ProGuard shrinks, optimizes and obfuscates your code, which reduces your app's size. By removing unused code and reducing the size of classes, fields, and methods, ProGuard helps to minimize the footprint of your app without sacrificing functionality. Additionally, ProGuard’s obfuscation feature enhances security by making reverse engineering more difficult. You can refer to the official documentation for more information.
Recommended Practices:
Enable ProGuard: To enable ProGuard in your project, ensure that yourproguard-rules.profile is properly configured, and add the following lines to yourbuild.gradlefile:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Add Keep Rules for VideoSDK: R8 removes or renames the SDK'svideosdk.orgclasses unless you keep them. Add these rules to yourandroid/app/proguard-rules.profile:
-keep class videosdk.org.** { *; }
-dontwarn videosdk.org.**
Keep the -dontwarn line, because the keep rule alone fails the R8 step with a missing-class error.
Customize ProGuard Rules: Carefully review and customize ProGuard rules in the proguard-rules.pro file to avoid stripping essential code. For example, to keep a specific class, add:
-keep class com.example.myapp.MyClass { *; }
If you encounter an issue after enabling ProGuard rules, refer to our Known Issues.
Got a Question? Ask us on discord

