Skip to content

Commit 5573241

Browse files
committed
re-launch emulator is not found, but still in running state
1 parent f73d608 commit 5573241

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/processing/mode/android/AndroidRunner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class AndroidRunner implements DeviceListener {
4545
protected PrintStream sketchErr;
4646
protected PrintStream sketchOut;
4747

48+
protected boolean showedSlowEmuWarning = false;
4849

4950
public AndroidRunner(AndroidBuild build, RunnerListener listener) {
5051
this.build = build;
@@ -97,7 +98,8 @@ public boolean launch(Future<Device> deviceFuture, int comp, boolean emu) {
9798
// this stopped working with Android SDK tools revision 17
9899
if (!device.installApp(build, listener)) {
99100
listener.statusError("Lost connection with " + devStr + " while installing. Try again.");
100-
if (emu) {
101+
if (emu && !showedSlowEmuWarning) {
102+
showedSlowEmuWarning = true;
101103
// More detailed message when using the emulator, to following discussion in
102104
// https://code.google.com/p/android/issues/detail?id=104305
103105
Messages.showWarning("The emulator is slooow...",

src/processing/mode/android/Devices.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,33 @@ public Device call() throws Exception {
124124
}
125125

126126

127-
private final Device blockingGetEmulator(File sdkToolsPath, final boolean wear, final boolean gpu) {
128-
// System.out.println("going looking for emulator");
127+
private final Device blockingGetEmulator(final File sdkToolsPath,
128+
final boolean wear, final boolean gpu) {
129129
String port = AVD.getPort(wear);
130130
Device emu = find(true, port);
131131
if (emu != null) {
132-
// System.out.println("found emu " + emu);
133132
return emu;
134133
}
135-
// System.out.println("no emu found");
136134

137135
EmulatorController emuController = EmulatorController.getInstance(wear);
138-
// System.out.println("checking emulator state");
136+
if (emuController.getState() == State.RUNNING) {
137+
// The emulator is in running state, but did not find any emulator device,
138+
// to the most common cause is that it was closed, so we will re-launch it.
139+
emuController.setState(State.NOT_RUNNING);
140+
}
141+
139142
if (emuController.getState() == State.NOT_RUNNING) {
140143
try {
141-
// System.out.println("not running, gonna launch");
142144
emuController.launch(sdkToolsPath, wear, gpu); // this blocks until emulator boots
143-
// System.out.println("not just gonna, we've done the launch");
144145
} catch (final IOException e) {
145146
System.err.println("Problem while launching emulator.");
146147
e.printStackTrace(System.err);
147148
return null;
148149
}
149150
} else {
150-
System.out.println("Emulator is " + emuController.getState() +
151-
", which is not expected.");
152-
151+
return null;
153152
}
154-
// System.out.println("and now we're out");
155153

156-
// System.out.println("Devices.blockingGet thread is " + Thread.currentThread());
157154
while (!Thread.currentThread().isInterrupted()) {
158155
// System.err.println("AndroidEnvironment: looking for emulator in loop.");
159156
// System.err.println("AndroidEnvironment: emulatorcontroller state is "

src/processing/mode/android/EmulatorController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.CountDownLatch;
2727

2828
import processing.app.Base;
29+
import processing.app.Platform;
2930
import processing.app.Preferences;
3031
import processing.app.exec.*;
3132

@@ -82,7 +83,7 @@ synchronized public void launch(File sdkToolsPath, boolean wear, boolean gpu) th
8283
}
8384
}
8485

85-
// See http://developer.android.com/guide/developing/tools/emulator.html
86+
// https://developer.android.com/studio/run/emulator-commandline.html
8687
String avdName;
8788
if (wear) {
8889
avdName = AVD.wearAVD.name;
@@ -93,9 +94,8 @@ synchronized public void launch(File sdkToolsPath, boolean wear, boolean gpu) th
9394
// https://developer.android.com/studio/run/emulator-acceleration.html#accel-graphics
9495
String gpuFlag = gpu ? "auto" : "off";
9596

96-
File emulatorPath = new File(sdkToolsPath, "emulator");
97-
if(!emulatorPath.exists())
98-
emulatorPath = new File(sdkToolsPath, "emulator.exe"); //Windows
97+
File emulatorPath = Platform.isWindows() ? new File(sdkToolsPath, "emulator.exe") :
98+
new File(sdkToolsPath, "emulator");
9999
final String[] cmd = new String[] {
100100
emulatorPath.getCanonicalPath(),
101101
"-avd", avdName,

0 commit comments

Comments
 (0)