avenmore
avenmore

Reputation: 2875

How to start an Android virtual device without seeing emulator.exe window

I want to create a shortcut to start a particular AVD with specific parameters. If I create a batch file with start emulator.exe -avd myavd the emulator.exe command window shows and remains after the device is started. Closing the emulator.exe window closes the device.

How can I start a device without seeing this window like the AVD Manager or Eclipse does?

Upvotes: 8

Views: 4956

Answers (4)

Omer Eliyahu
Omer Eliyahu

Reputation: 19

Using .ps1 File

You can start the emulator without having the command window to show by using this powershell command:

Start-Process "emulator" -ArgumentList "-avd YourAVD" -WindowStyle Hidden

Using .bat File

You can achieve doing so by calling the powershell command through the .bat file:

powershell -command "Start-Process \"emulator\" -ArgumentList \"-avd YourAVD\" -WindowStyle Hidden"

Note:

In order to call the emulator you must first add the following folder to Path:
%localappdata%\Android\Sdk\emulator

Upvotes: 0

Alex Angelico
Alex Angelico

Reputation: 4035

I found an easy workaround, using SilentCMD

Create batch file, in my case my AVDs is called "PIXEL_MARSHMALLOW_6" so my batch is called emulator_marshmallow.cmd:

REM emulator_marshmallow.cmd    
emulator @PIXEL_MARSHMALLOW_6

Run

c:\>SilentCMD emulator_marshmallow.cmd

This runs the emulator and the cmd.exe windows is hidden. BTW, I found many other utilities like SilentCMD here: https://www.raymond.cc/blog/hidden-start-runs-batch-files-silently-without-flickering-console/

Upvotes: 1

Steve Waring
Steve Waring

Reputation: 3023

Create this java substituting the details for the avd you want:

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class AVDs
{       
    public static void main(String[] args) throws IOException
    {
        List<String> avdCmd = new ArrayList<String>(args.length + 1);
        avdCmd.add("C:\\Users\\Steve\\AppData\\Local\\Android\\sdk\\tools\\emulator.exe");
        for (String cmdarg: args)
        {
            avdCmd.add(cmdarg);
        }
        ProcessBuilder launch = new ProcessBuilder();
        launch.inheritIO().command(avdCmd).start();
    }
}

Then use this as your shortcut:

"C:\Program Files\Java\jre1.8.0_40\bin\javaw.exe" -cp "S:\ADT workspace\AVDs\bin" AVDs -timezone Europe/London -avd Lollipop -scale 0.5

Substituting your classpath, or removing it if you don't need it. Make sure you use a path to javaw, don't just use java.

Upvotes: 3

Steve
Steve

Reputation: 4635

As far as I know you can't. Even if you run emulator -avd Nexus_One from the Windows run dialog a command line like window opens. I can't see any options to hide this, like a silent mode either (running emulator -help shows available options). Eclipse has its own command line built in, so you don't see another window.

Upvotes: 0

Related Questions