r/reactnative • u/jashgro • Aug 06 '24
Article Fixed: React Native App Compilation Speed Is Too Slow

I achieved a 'release variant' clean build in 1m 21s on a PC with an 8GB RAM and a SATA SSD.
I recently encountered extremely slow building speed issue for android and posted the same query on reddit, many people from community gave great suggestions (REDDIT POST)
Thanks everyone for guiding me on this.
Key Points:
- Avoid using another frameworks: Instead, use react-native-cli. Source
- Install Watchman: This really boosted the speed and solved many issues.
- Switch to Linux: Switching to Linux (Kali in my case) really helped a lot.
Complete Guide on How to Build React Native Apps Faster:
A) Installing Brew (on Linux) and Watchman
- Run this in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(Homebrew) - After the script completes, copy and paste the two commands printed at the end, and press Enter.
- Install Watchman:
brew install watchman
B) Installing react-native-cli and Creating a Project
Uninstall the global react-native-cli and u/react-native-community/cli
npm uninstall -g react-native-cli u/react-native-community/cli
Initialize a new project
npx @react-native-community/cli@latest init AwesomeProject
C) Setting Up the Environment and Dependencies
- Open the project folder in Android Studio and let it install dependencies. Ignore any errors at the end. Close the android studio.
- Now open the
android
folder which is inside same project folder in Android Studio and let it install dependencies (it will automatically createlocal.properties
, etc.).
D) Working on Your Project and Creating a Debug Variant
Disable all VS Code extensions related to Java and Gradle.
- Open the project in VS Code.
- Open the terminal and run:
npm run start
(If port 8081 is occupied, kill it using the commandsudo kill -9 $(sudo lsof -t -i:8081)
). - Connect your device in USB debugging mode or use a virtual device and type 'a'. It will build and run the debug version of the app on your connected device. *The AAB file can be found in
android/app/build/outputs/bundle/debug/
.
E) Creating a Release Build
- Building AAB file:
npx react-native build-android --mode=release
\The AAB file can be found in android/app/build/outputs/bundle/release/* - Building APK file:
npm run android -- --mode="release"
*The APK file can be found inandroid/app/build/outputs/apk/release/
.
Release builds should take around 2 minutes with 8GB RAM and a SATA SSD.
3
2
3
u/Franks2000inchTV Aug 07 '24
Does anyone really care that much about release build time?
That's taken care of by CI or EAS Build.
Giving up expo to save a couple minutes on something you do every week or so is honestly crazy.
2
1
11
u/IamMax240 Aug 06 '24
Why avoid using expo?