0
0
React-nativeHow-ToBeginner ยท 4 min read

How to Build React Native Apps for Android: Step-by-Step Guide

To build a React Native app for Android, first ensure you have Android Studio and the Android SDK installed. Then run npx react-native run-android in your project folder to compile and launch the app on an emulator or connected device.
๐Ÿ“

Syntax

The main command to build and run a React Native app on Android is:

  • npx react-native run-android: Builds the app and installs it on a connected Android device or emulator.
  • Ensure your Android environment is set up with ANDROID_HOME or ANDROID_SDK_ROOT and SDK tools.
bash
npx react-native run-android
Output
BUILD SUCCESSFUL in 30s Installing build/app/outputs/apk/debug/app-debug.apk on device... Starting the app on device...
๐Ÿ’ป

Example

This example shows how to build and run a React Native app on Android using the command line after setting up your environment.

bash
cd MyReactNativeApp
npx react-native run-android
Output
Starting JS server... Building and installing the app on Android device/emulator... App launched successfully.
โš ๏ธ

Common Pitfalls

Common issues include:

  • Not having Android SDK or emulator installed.
  • Missing environment variables like ANDROID_HOME or ANDROID_SDK_ROOT.
  • Device not connected or emulator not running.
  • Build failures due to outdated Gradle or dependencies.

Always check your setup and run adb devices to confirm your device is recognized.

bash
Wrong:
npx react-native run-ios

Right:
npx react-native run-android
๐Ÿ“Š

Quick Reference

CommandPurpose
npx react-native run-androidBuilds and runs app on Android device/emulator
adb devicesLists connected Android devices
emulator -list-avdsLists available Android emulators
npx react-native startStarts the Metro bundler server
โœ…

Key Takeaways

Run npx react-native run-android to build and launch your app on Android.
Make sure Android Studio and SDK are installed and environment variables set.
Use adb devices to verify your device or emulator is connected.
Keep your Gradle and dependencies updated to avoid build errors.