protected void startAndroidEmulator ( ) throws MojoExecutionException { parseParameters ( ) ; CommandExecutor executor = CommandExecutor . Factory . createDefaultCommmandExecutor ( ) ; executor . setLogger ( this . getLog ( ) ) ; try { String filename ; if ( isWindows ( ) ) { filename = writeEmulatorStartScriptWindows ( ) ; } else { filename = writeEmulatorStartScriptUnix ( ) ; } final AndroidDebugBridge androidDebugBridge = initAndroidDebugBridge ( ) ; if ( androidDebugBridge . isConnected ( ) ) { waitForInitialDeviceList ( androidDebugBridge ) ; List < IDevice > devices = Arrays . asList ( androidDebugBridge . getDevices ( ) ) ; int numberOfDevices = devices . size ( ) ; getLog ( ) . info ( "Found " + numberOfDevices + " devices connected with the Android Debug Bridge" ) ; IDevice existingEmulator = findExistingEmulator ( devices ) ; if ( existingEmulator == null ) { getLog ( ) . info ( START_EMULATOR_MSG + filename ) ; executor . executeCommand ( filename , null ) ; getLog ( ) . info ( START_EMULATOR_WAIT_MSG + parsedWait ) ; // wait for the emulator to start up boolean booted = waitUntilDeviceIsBootedOrTimeout ( androidDebugBridge ) ; if ( booted ) { getLog ( ) . info ( "Emulator is up and running." ) ; unlockEmulator ( androidDebugBridge ) ; } else { throw new MojoExecutionException ( "Timeout while waiting for emulator to startup." ) ; } } else { getLog ( ) . info ( String . format ( "Emulator already running [Serial No: '%s', AVD Name '%s']. " + "Skipping start and wait." , existingEmulator . getSerialNumber ( ) , existingEmulator . getAvdName ( ) ) ) ; } } } catch ( Exception e ) { throw new MojoExecutionException ( "" , e ) ; } }
Start the Android Emulator with the specified options .