How do I launch the Android emulator from the command line?
If your project is ready to launch but you don’t have any Android Virtual Devices (AVDs) created, here’s a simple guide to set everything up using the command line. Here is step by step procedure . How do I launch the Android emulator from the command line?
Step 1: Create a New Virtual Device (AVD)
You can create an AVD using either the command line or the Android Virtual Device Manager (GUI).
Using Command Line:
Run the following command:
android create avd -n <name> -t <targetID>
- Replace
<name>
with your desired AVD name. - Replace
<targetID>
with the API level or target ID for the platform you need.
For example:
android create avd -n MyAVD -t 30
Using GUI:
Run this command to open the AVD Manager:
android avd
From the GUI, you can easily create and manage your AVDs.
Tip: Check official documentation for more details on AVD management via GUI or command line.
Step 2: Run the AVD
Once the AVD is created, you can start it either through the command line or the GUI.
Using Command Line:
Run the following command to launch your AVD:
emulator -avd <name>
For example:
emulator -avd MyAVD
Using GUI:
You can launch the AVD directly from the AVD Manager.
Note: The emulator may take some time to fully load.
Step 3: Install Your Application
Once the emulator is running, you need to install your APK file.
Option 1: Use Ant Script (during development):
If you’re using Ant for building your project, simply choose the install
target.
Option 2: Install Manually via Command Line:
Run the following command:
adb install <path-to-your-APK>
For example:
adb install /path/to/your/app-debug.apk
Step 4: Launch Your Application
Now that your app is installed, you can launch it just like on a real device. Open the emulator and tap the app icon in the launcher.
Alternative Command Line Method:
You can also launch the app using the following command:
adb shell am start -a android.intent.action.MAIN -n <package>/<activity-class>
For example:
adb shell am start -a android.intent.action.MAIN -n org.sample.helloworld/org.sample.helloworld.HelloWorld
Simplified Alternative:
You can replace the full activity path with just the activity name:
adb shell am start -a android.intent.action.MAIN -n org.sample.helloworld/.HelloWorld
With these steps, you can efficiently launch and test your Android app on a virtual device without needing a GUI-based workflow.
List all your emulators:
emulator -list-avds
Run one of the listed emulators with -avd
flag:
emulator -avd name-of-your-emulator
where the emulator
executable is under:
${ANDROID_SDK}/tools/emulator
Or, for newer SDKs, try:
cd ${ANDROID_HOME}/emulator
emulator -avd name-of-your-emulator