Running React Native on Android Emulator: A Step-by-Step Guide

Running React Native on Android Emulator: A Step-by-Step Guide

30 November 2024 Stephan Petzl Leave a comment Tech-Help

Running a React Native application on an Android emulator can sometimes be challenging. If you encounter issues such as “Could not run adb reverse” or “Could not install the app on the device,” you’re not alone. This guide provides a comprehensive solution to troubleshoot and resolve these problems.

Step 1: Ensure SDK Tools and Platform are Updated

One common issue arises from outdated SDK components. To address this:

  • Update Android SDK Tools to the latest version.
  • Ensure Android SDK Platform-tools and Build-tools are up-to-date.
  • Check the Android Support Repository under the Extras folder in the SDK Manager.

Make sure the Android API version matches the installed SDK Build-tools and Platform-tools versions.

Step 2: Configure Environment Variables

On macOS, setting the correct environment variables is crucial:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

Add these lines to your ~/.zsh_profile or ~/.bash_profile and run source ~/.zsh_profile to update the terminal session.

Step 3: Verify Emulator and ADB Connection

Ensure the emulator is running and recognized by ADB:

  • Launch the emulator using the AVD Manager in Android Studio.
  • Verify the emulator connection with adb devices.

If not recognized, consider installing platform tools using brew install android-platform-tools on macOS.

Step 4: Clean and Rebuild the Project

If issues persist, cleaning the build files may help. Navigate to the Android directory and execute:

chmod +x gradlew
./gradlew clean

Then, return to the project root and run npx react-native run-android to rebuild and deploy the app.

Additional Resources

For more detailed instructions on setting up your development environment, visit our Getting Started guide.

Enhance Testing with Repeato

While addressing emulator issues, consider leveraging Repeato for your testing needs. Repeato is a no-code test automation tool for iOS and Android that simplifies creating, running, and maintaining automated tests. Its integration with ADB allows precise execution of commands, making it an ideal solution for efficient and robust app testing. Learn more about Repeato on our Android Testing Tool page.

Like this article? there’s more where that came from!