0
0
Android-kotlinHow-ToBeginner ยท 4 min read

How to Run Android App on Emulator: Step-by-Step Guide

To run an Android app on an emulator, first create and start an Android Virtual Device (AVD) in Android Studio. Then, build and run your app by clicking the Run button or using the command ./gradlew installDebug followed by adb shell am start to launch it on the emulator.
๐Ÿ“

Syntax

Running an Android app on an emulator involves these main steps:

  • Create and start an emulator: Use Android Virtual Device (AVD) Manager in Android Studio or the command line.
  • Build and install the app: Use ./gradlew installDebug to install the app on the running emulator.
  • Launch the app: Use adb shell am start -n package_name/activity_name to open the app.
bash
emulator -avd Your_AVD_Name
./gradlew installDebug
adb shell am start -n com.example.app/.MainActivity
๐Ÿ’ป

Example

This example shows how to start an emulator named Pixel_4_API_30, install the debug build of your app, and launch its main activity.

bash
emulator -avd Pixel_4_API_30
./gradlew installDebug
adb shell am start -n com.example.myapp/.MainActivity
Output
Starting emulator Pixel_4_API_30... Installing app... Launching app com.example.myapp/.MainActivity...
โš ๏ธ

Common Pitfalls

Common mistakes when running apps on emulator include:

  • Not starting the emulator before installing the app, causing installation failure.
  • Using wrong package or activity names in the adb shell am start command.
  • Emulator performance issues if hardware acceleration is disabled.
  • Forgetting to select the emulator device in Android Studio before running.
bash
Wrong command example:
adb shell am start -n com.example.wrong/.MainActivity

Correct command example:
adb shell am start -n com.example.myapp/.MainActivity
๐Ÿ“Š

Quick Reference

Summary tips for running Android apps on emulator:

  • Always start your emulator before installing the app.
  • Use adb devices to check if emulator is connected.
  • Use correct package and activity names to launch the app.
  • Use Android Studio's Run button for a simple workflow.
โœ…

Key Takeaways

Start the Android emulator before installing or running your app.
Use correct package and activity names with adb to launch the app.
Android Studio's Run button simplifies running apps on emulator.
Check emulator connection with adb devices command.
Enable hardware acceleration for better emulator performance.