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) Managerin Android Studio or the command line. - Build and install the app: Use
./gradlew installDebugto install the app on the running emulator. - Launch the app: Use
adb shell am start -n package_name/activity_nameto 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 startcommand. - 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 devicesto check if emulator is connected. - Use correct package and activity names to launch the app.
- Use Android Studio's
Runbutton 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.