7

As I'm not developing my app with Android Studio, but I'm still using the Android emulator.

What's a nice way for me start up my emulator without doing this?

  1. Open Android Studio
  2. Open some project
  3. Click the AVD Manager button

I'm not looking for a complete CI replacement, but if there's a long command I can run to open the GUI I'm happy.

Jeggy
  • 1,474
  • 1
  • 19
  • 35
  • Does this answer your question? [Run AVD Emulator without Android Studio](https://stackoverflow.com/questions/42718973/run-avd-emulator-without-android-studio) – Bink Oct 07 '21 at 16:29

3 Answers3

6

Cd to your Android SDK location using PowerShell

cd C:\Users\UserName\AppData\Local\Android\Sdk\tools

and type

.\emulator.exe -list-avds

this will show your available avds, choose your device copy the name and replace the following

.\emulator.exe -avd "<virtualDeviceName>"

Eg:

.\emulator.exe -avd "Pixel_2_API_27"

You can simply create a .bat file

@echo off
cd C:\Users\UserName\AppData\Local\Android\Sdk\tools
@echo Running the emulator
.\emulator.exe -avd "Pixel_2_API_27"
  • 1
    There's two big issues here. First things first, the `emulator.exe` file is'nt in the `\tools` folder but in the `\emulator` folder. Secondly a batch file will never have a `#!/bin/sh` hashbang in it. You should replace it with `@echo off` instead. Hashbangs are for bash scripts. – TwystO Aug 31 '20 at 12:25
  • Thanks for the instructions, in my case both directories work IDK :/ – Sudaraka Senevirathne Sep 01 '20 at 18:46
5

What about a script that show current avds defined and let you choose which one start ? I called it avdmanager.bat in root of SDK (variable ANDROID_HOME set on SDK root needed):

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=0
FOR /F "tokens=* USEBACKQ" %%F IN (`%ANDROID_HOME%\emulator\emulator.exe -list-avds`) DO (
  SET /a count=!count!+1
  SET var!count!=%%F
)
for /l %%i in (1,1,%count%) do echo %%i) !var%%i!
@echo digit number of virtual machine to run or 'q' to quit
set /p choice=""
if "%choice%"=="q" goto end
@echo !var%choice%!
%ANDROID_HOME%\emulator\emulator.exe -avd !var%choice%!
:end
ENDLOCAL
alrama
  • 618
  • 11
  • 17
3

Just a minor fix with the command -list-avds in @alrama's answer (the extra space), I cannot add comments yet.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=0
FOR /F "tokens=* USEBACKQ" %%F IN (`%ANDROID_HOME%\emulator\emulator.exe -list-avds`) DO (
  SET /a count=!count!+1
  SET var!count!=%%F
)
for /l %%i in (1,1,%count%) do echo %%i) !var%%i!
@echo digit number of virtual machine to run or 'q' to quit
set /p choice=""
if "%choice%"=="q" goto end
@echo !var%choice%!
%ANDROID_HOME%\emulator\emulator.exe -avd !var%choice%!
:end
ENDLOCAL
Votagus
  • 544
  • 6
  • 9