Skip to content

Instantly share code, notes, and snippets.

@velrino
Created March 4, 2025 17:48
Show Gist options
  • Select an option

  • Save velrino/984cc3807b1fe3397f72b7260c18a7f9 to your computer and use it in GitHub Desktop.

Select an option

Save velrino/984cc3807b1fe3397f72b7260c18a7f9 to your computer and use it in GitHub Desktop.
React Native Build & Deployment Guide

πŸ“± React Native Android Build & Deployment Guide

πŸ”„ Reset Metro Bundler Cache

Before building the application, it's recommended to clear the Metro Bundler cache to avoid potential issues with stale or corrupted data:

npm start -- --reset-cache

This command:

  • Starts the Metro Bundler, which compiles JavaScript code for React Native.
  • Clears the cache to remove any outdated files, preventing inconsistencies during development.
  • Helps resolve issues related to stale dependencies or incorrect asset loading.

πŸ“± Building and Distributing React Native Apps for Android

This document outlines the steps to build and distribute a React Native app for Android, including generating an APK (for direct installation) and an AAB (Android App Bundle) (for distribution on the Google Play Store).


πŸ”§ 1. Building the Application

Before generating the APK or AAB, we need to compile the code and prepare the app's assets.

πŸ“¦ 1.1 Build the Android Application

npx react-native build-android --mode=release

This command compiles the application in release mode.

πŸ“œ 1.2 Generate the JavaScript Bundle

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle

This command packages the JavaScript code for production.

🧹 1.3 Clean Previous Build (Optional)

cd android/
./gradlew clean

This command removes previous builds to avoid conflicts.


πŸ“¦ 2. Generating the APK (For Direct Installation)

If you want to generate an APK for testing or manual distribution:

./gradlew assembleRelease

This will create the APK at:

android/app/build/outputs/apk/release/app-release.apk

πŸ“² 2.1 Install the APK on a Device

adb install android/app/build/outputs/apk/release/app-release.apk

This command installs the APK on a connected device via ADB.

πŸ“‚ 2.2 Open the APK Location

open android/app/build/outputs/apk/release

This will open the folder where the APK is saved.


🎁 3. Generating the AAB (For Play Store Publishing)

If you want to upload the app to the Google Play Store, you need to generate an Android App Bundle (AAB):

./gradlew bundleRelease

This will create an AAB file at:

app/build/outputs/bundle/release/app-release.aab

This file should be uploaded to the Google Play Console for distribution.


🎯 Conclusion

  • Use APK for direct installation.
  • Use AAB for Play Store publishing.
  • Always run ./gradlew clean before building to avoid cache issues.

Your app is now ready for testing or release! πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment