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-cacheThis 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.
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).
Before generating the APK or AAB, we need to compile the code and prepare the app's assets.
npx react-native build-android --mode=releaseThis command compiles the application in release mode.
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundleThis command packages the JavaScript code for production.
cd android/
./gradlew cleanThis command removes previous builds to avoid conflicts.
If you want to generate an APK for testing or manual distribution:
./gradlew assembleReleaseThis will create the APK at:
android/app/build/outputs/apk/release/app-release.apk
adb install android/app/build/outputs/apk/release/app-release.apkThis command installs the APK on a connected device via ADB.
open android/app/build/outputs/apk/releaseThis will open the folder where the APK is saved.
If you want to upload the app to the Google Play Store, you need to generate an Android App Bundle (AAB):
./gradlew bundleReleaseThis 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.
- Use APK for direct installation.
- Use AAB for Play Store publishing.
- Always run
./gradlew cleanbefore building to avoid cache issues.
Your app is now ready for testing or release! π