diff --git a/android/todo.txt b/android/todo.txt index 44cab1bc3..00b2ae931 100644 --- a/android/todo.txt +++ b/android/todo.txt @@ -1,4 +1,5 @@ 0204 android +X fix problem with android emulator launching on Windows _ if a sketch asks for android mode but it's not available diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index dc41cac6e..898397b88 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -56,8 +56,8 @@ public class Base { /** Set true if this a proper release rather than a numbered revision. */ static public boolean RELEASE = false; /** True if heavy debugging error/log messages are enabled */ - // static public boolean DEBUG = false; - static public boolean DEBUG = true; + static public boolean DEBUG = false; + //static public boolean DEBUG = true; static HashMap platformNames = new HashMap(); diff --git a/app/src/processing/mode/android/Devices.java b/app/src/processing/mode/android/Devices.java index b1922fa46..da0305ab7 100644 --- a/app/src/processing/mode/android/Devices.java +++ b/app/src/processing/mode/android/Devices.java @@ -45,11 +45,9 @@ class Devices { System.out.flush(); try { AndroidSDK.runADB("kill-server"); - // System.err.println("OK."); } catch (final Exception e) { - System.err.println("failed."); - System.err.println(); - e.printStackTrace(System.err); + System.err.println("Devices.killAdbServer() failed."); + e.printStackTrace(); } } @@ -60,26 +58,20 @@ class Devices { } // killAdbServer(); Runtime.getRuntime().addShutdownHook( - new Thread("AndroidEnvironment Shutdown") { - @Override + new Thread("processing.mode.android.Devices Shutdown") { public void run() { - shutdown(); + //System.out.println("Shutting down Devices"); + //System.out.flush(); + for (Device device : new ArrayList(devices.values())) { + device.shutdown(); + } + // Don't do this, it'll just make Eclipse and others freak out. + //killAdbServer(); } }); } - private void shutdown() { -// System.out.println("Shutting down Devices"); -// System.out.flush(); - for (Device device : new ArrayList(devices.values())) { - device.shutdown(); - } - // Don't do this, it'll just make Eclipse and others freak out. -// killAdbServer(); - } - - public Future getEmulator() { final Callable androidFinder = new Callable() { public Device call() throws Exception { diff --git a/app/src/processing/mode/android/EmulatorController.java b/app/src/processing/mode/android/EmulatorController.java index 25727b865..927862960 100644 --- a/app/src/processing/mode/android/EmulatorController.java +++ b/app/src/processing/mode/android/EmulatorController.java @@ -2,9 +2,13 @@ package processing.mode.android; import java.io.IOException; import java.util.concurrent.CountDownLatch; + +import processing.app.Base; import processing.app.Preferences; import processing.app.exec.LineProcessor; +import processing.app.exec.ProcessHelper; import processing.app.exec.ProcessRegistry; +import processing.app.exec.ProcessResult; import processing.app.exec.StreamPump; import processing.core.PApplet; @@ -57,10 +61,13 @@ class EmulatorController { "-no-boot-anim" }; //System.err.println("EmulatorController: Launching emulator"); - //System.out.println(processing.core.PApplet.join(cmd, " ")); + if (Base.DEBUG) { + System.out.println(processing.core.PApplet.join(cmd, " ")); + } + //ProcessResult adbResult = new ProcessHelper(adbCmd).execute(); final Process p = Runtime.getRuntime().exec(cmd); ProcessRegistry.watch(p); - new StreamPump(p.getInputStream(), "emulator: ").addTarget(System.out).start(); +// new StreamPump(p.getInputStream(), "emulator: ").addTarget(System.out).start(); // if we've gotten this far, then we've at least succeeded in finding and // beginning execution of the emulator, so we are now officially "Launched" @@ -121,8 +128,9 @@ class EmulatorController { } } System.err.println("EmulatorController: Emulator never booted. " + state); - } catch (final Exception e) { - System.err.println("While waiting for emulator to boot " + e); + } catch (Exception e) { + System.err.println("Exception while waiting for emulator to boot:"); + e.printStackTrace(); p.destroy(); } finally { latch.countDown(); @@ -132,24 +140,23 @@ class EmulatorController { new Thread(new Runnable() { public void run() { try { - try { - p.waitFor(); - // final int result = p.waitFor(); - // System.err - // .println("Emulator process exited " - // + ((result == 0) ? "normally" : " with status " + result) - // + "."); - } catch (final InterruptedException e) { - System.err.println("Emulator was interrupted."); - } finally { - p.destroy(); - ProcessRegistry.unwatch(p); + final int result = p.waitFor(); + // On Windows (as of SDK tools 15), emulator.exe process will terminate + // immediately, even though the emulator itself is launching correctly. + // However on OS X and Linux the process will stay open. + if (result != 0) { + System.err.println("Emulator process exited with status " + result + "."); + setState(State.NOT_RUNNING); } - } finally { + } catch (InterruptedException e) { + System.err.println("Emulator was interrupted."); setState(State.NOT_RUNNING); + } finally { + p.destroy(); + ProcessRegistry.unwatch(p); } } - }, "EmulatorController: Process manager").start(); + }, "EmulatorController: emulator process waitFor()").start(); try { latch.await(); } catch (final InterruptedException drop) {