Setting Up an Android Simulator for Expo: A Step-by-Step Guide

When building React Native apps with Expo, testing your app on an Android emulator is a crucial part of the development process. In this guide, I'll walk you through how to set up and launch an Android Virtual Device (AVD) using Android Studio, using the latest "Ladybug Feature Drop" version.

Why Use an Android Simulator?

An Android emulator lets you run a virtual Android device on your computer. This is particularly useful when you:

  • Don't have a physical Android device handy:
    The emulator lets you test and debug your app without needing an actual device.

  • Want to quickly test changes across different Android versions and configurations:
    Easily switch between various device profiles to ensure compatibility and performance across multiple Android environments.

  • Need a consistent testing environment integrated with your Expo workflow:
    With an emulator, you can simulate real device behavior, ensuring that your Expo app runs as expected.

Important:
Before testing your Expo app on the Android emulator, make sure the emulator is completely launched and running. If you try to run your app using npx expo run:android before the emulator has fully started, the app might not load properly, and you won't be able to see it on the virtual device.

Step 1: Install Android Studio

If you haven't already, download and install Android Studio. This IDE comes bundled with the Android SDK and the AVD Manager, which you'll use to create and manage your emulators.

For macOS

  1. Download Android Studio:
    Go to the Android Studio download page. Click the Download Android Studio button.

  2. Install Android Studio:

    • Once the DMG file is downloaded, open it.

    • Drag the Android Studio icon into your Applications folder.

    • Open Android Studio from your Applications folder.

    • Follow the setup wizard, which will guide you through the initial configuration and the installation of the Android SDK and other required components.

For Windows

  1. Download Android Studio:
    Visit the Android Studio download page and click the Download Android Studio button.

  2. Install Android Studio:

    • Once the installer (an .exe file) is downloaded, run it.

    • Follow the installation wizard, which will prompt you to select components, choose an installation path, and install the Android SDK.

    • After installation, launch Android Studio and complete the initial setup wizard.

Step 2: Open the Device Manager (AVD Manager) in Android Studio

  1. Since we’re using Android Studio specifically to open an Android emulator, follow these instructions:

    From the Welcome Screen (Recommended for New Users):

    • After launching Android Studio for the first time, you'll see the Welcome Screen.

    • Look for the More Actions button or gear icon, and select Device Manager (also known as AVD Manager).

    • This will open a list of available emulators, where you can create and launch a new Android Virtual Device (AVD).

(Alternative) From Within a Project:

  • If you ever open an existing project in Android Studio, you can access the Device Manager by navigating to Tools > Device Manager in the top menu.

Step 3: Create or Select an Android Virtual Device (AVD)

  • Select an Existing Device:
    If you already have a virtual device configured, simply click the Play button next to it to launch the emulator.

  • Create a New Device:
    If no device exists or you want to create a new one, click Create Device. Follow these steps:

    • Choose a Hardware Profile:
      Select a device profile that matches your target device (e.g., Pixel 3 or Nexus 5X).

    • Select a System Image:
      Pick a system image that suits your development needs. We recommend selecting one with the Google APIs.

    • Finish:
      Complete the wizard to create your new AVD.

Step 4: Launch the Emulator

Once your AVD is configured, simply click the Play icon in the Device Manager to start the emulator. Alternatively, you can launch the emulator from the command line by listing available devices and starting your chosen one:

# List all available AVDs
emulator -list-avds

# Launch a specific AVD (replace <your_avd_name> with the device name)
emulator -avd <your_avd_name>

Step 5: Running Your Expo App on the Emulator

With your emulator up and running, switch back to your project directory and execute:

npx expo run:android

Expo will detect the running emulator and install your app on it. This command builds your native Android project (generated via Expo’s prebuild if needed) and launches the app on the emulator.

Troubleshooting Tips

  • Emulator Not Launching?

    • Ensure your AVD is properly configured and that your system meets the hardware requirements for virtualization.

    • If you're having trouble launching the emulator—such as slow performance, crashes, or it not starting at all—it might be because virtualization isn’t enabled on your machine. For Windows, check your BIOS/UEFI for Intel VT-x (or AMD-V). On macOS, virtualization is typically enabled by default.

Expo Doesn’t Detect the Emulator?

  • Make sure the emulator is fully booted up before running npx expo run:android.

Command Line Option:

  • If you prefer not to deal with Android Studio’s UI, launching the emulator from the terminal (as shown above) is a quick alternative.

Conclusion

Setting up an Android emulator with Android Studio with the latest "Ladybug Feature Drop" is straightforward once you get the hang of it. With your emulator running, you can rapidly test and iterate on your Expo project, ensuring your app works smoothly on Android devices.

Feel free to leave comments or share your experiences setting up your Android simulator. Happy coding!