Error starting command: monkey --port 12345 卡死的问题

七月 02, 2014 2:18:08 下午 com.sprd.tool.traverse.TraverseTool$MyClock run
警告: Time up!Clock is closing!
七月 02, 2014 2:18:23 下午 com.sprd.tool.traverse.Device getWindowId
警告: getWindowId()--runtimeException
七月 02, 2014 2:18:23 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: quit.
七月 02, 2014 2:18:23 下午 com.sprd.tool.traverse.UIOrderTraverseTool traverseWindow
信息: change type NEW
七月 02, 2014 2:18:25 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: wake.
七月 02, 2014 2:18:25 下午 com.sprd.tool.traverse.Device startChimpDevice
警告: start monkeyrunner
七月 02, 2014 2:18:25 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: quit.
七月 02, 2014 2:18:28 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: quit.
七月 02, 2014 2:18:28 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: quit.
七月 02, 2014 2:18:28 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: quit.
七月 02, 2014 2:18:28 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: quit.
七月 02, 2014 2:18:28 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: quit.
七月 02, 2014 2:18:30 下午 com.android.chimpchat.ChimpManager sendMonkeyEventAndGetResponse
信息: Monkey Command: wake.
七月 02, 2014 2:18:40 下午 com.android.chimpchat.adb.AdbChimpDevice$1 run
信息: Error starting command: monkey --port 12345
com.android.ddmlib.ShellCommandUnresponsiveException
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:430)
    at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:347)
    at com.android.ddmlib.Device.executeShellCommand(Device.java:435)
    at com.android.chimpchat.adb.AdbChimpDevice$1.run(AdbChimpDevice.java:104)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)


hierarchyviewer输出:


02:17:57 E/hierarchyviewer: Timeout setting up port forwarding for 16442209010961
02:18:09 E/hierarchyviewer: Timeout checking status of view server on device 16442209010961
02:18:21 E/hierarchyviewer: Timeout starting view server on device 16442209010961
02:18:23 E/hierarchyviewer: Unable to debug device 16442209010961
public static boolean startViewServer(IDevice device, int port) {
    boolean[] result = new boolean[1];
    try {
      if (device.isOnline())
        device.executeShellCommand(buildStartServerShellCommand(port), new BooleanResultReader(result));
    }
    catch (TimeoutException e)
    {
      Log.e("hierarchyviewer", "Timeout starting view server on device " + device);
    } catch (IOException e) {
      Log.e("hierarchyviewer", "Unable to start view server on device " + device);
    } catch (AdbCommandRejectedException e) {
      Log.e("hierarchyviewer", "Adb rejected command to start view server on device " + device);
    } catch (ShellCommandUnresponsiveException e) {
      Log.e("hierarchyviewer", "Unable to execute command to start view server on device " + device);
    }
    return result[0];
  }
public static boolean isViewServerRunning(IDevice device)
  {
    boolean[] result = new boolean[1];
    try {
      if (device.isOnline()) {
        device.executeShellCommand(buildIsServerRunningShellCommand(), new BooleanResultReader(result));

        if (result[0] == 0) {
          ViewServerInfo serverInfo = loadViewServerInfo(device);
          if ((serverInfo != null) && (serverInfo.protocolVersion > 2))
            result[0] = true;
        }
      }
    }
    catch (TimeoutException e) {
      Log.e("hierarchyviewer", "Timeout checking status of view server on device " + device);
    } catch (IOException e) {
      Log.e("hierarchyviewer", "Unable to check status of view server on device " + device);
    } catch (AdbCommandRejectedException e) {
      Log.e("hierarchyviewer", "Adb rejected command to check status of view server on device " + device);
    } catch (ShellCommandUnresponsiveException e) {
      Log.e("hierarchyviewer", "Unable to execute command to check status of view server on device " + device);
    }

    return result[0];
  }
public static boolean startViewServer(IDevice device) {
    return startViewServer(device, 4939);
  }

  public static boolean startViewServer(IDevice device, int port) {
    boolean[] result = new boolean[1];
    try {
      if (device.isOnline())
        device.executeShellCommand(buildStartServerShellCommand(port), new BooleanResultReader(result));
    }
    catch (TimeoutException e)
    {
      Log.e("hierarchyviewer", "Timeout starting view server on device " + device);
    } catch (IOException e) {
      Log.e("hierarchyviewer", "Unable to start view server on device " + device);
    } catch (AdbCommandRejectedException e) {
      Log.e("hierarchyviewer", "Adb rejected command to start view server on device " + device);
    } catch (ShellCommandUnresponsiveException e) {
      Log.e("hierarchyviewer", "Unable to execute command to start view server on device " + device);
    }
    return result[0];
  }

private void setupViewServer() {
    DeviceBridge.setupDeviceForward(this.mDevice);
    if ((!DeviceBridge.isViewServerRunning(this.mDevice)) && 
      (!DeviceBridge.startViewServer(this.mDevice)))
    {
      try {
        Thread.sleep(2000L);
      } catch (InterruptedException e) {
      }
      if (!DeviceBridge.startViewServer(this.mDevice)) {
        Log.e("hierarchyviewer", "Unable to debug device " + this.mDevice);
        throw new RuntimeException("Could not connect to the view server");
      }
      return;
    }




程序会卡死。


C:\Documents and Settings\hui.qian>netstat -a -n | find /I "4939"
  TCP    127.0.0.1:4939         0.0.0.0:0              LISTENING

C:\Documents and Settings\hui.qian>netstat -aon |findstr "4939"
  TCP    127.0.0.1:4939         0.0.0.0:0              LISTENING       44588

C:\Documents and Settings\hui.qian>tasklist|findstr "44588"
adb.exe                    44588 Console                 0      2,260 K



发现4939的端口被adb.exe占用。


再次启动adb会报:


02:56:02 E/adb: ADB server didn't ACK
02:56:02 E/adb: * failed to start daemon *

解决adb报错的问题用

netstat -aon|findstr "5037"

然后根据结果中的最后一列里的PID来获取哪个进程占用

tasklist|findstr "21900"

Error starting command: monkey --port 12345 卡死的问题_第1张图片


得到了adb占用了这个端口。


taskkill /f /t /im adb.exe

Error starting command: monkey --port 12345 卡死的问题_第2张图片

C:\Documents and Settings\hui.qian>adb devices
List of devices attached
16442209010961  device

adb的问题解决。

==================================================================================================================================

对于

Error starting command: monkey --port 12345
的错误分析指出这个错误就是因为adb的12345不能被映射造成的,具体原因还没找到。现在只是粗暴的重启adb。

解决办法:


用Future的方式限制启动Monkeyrunner的时间,如果时间超出还没有启动,则重启adb。(以下代码仅供参考)


public void startChimpDevice() {
		ExecutorService exec = Executors.newFixedThreadPool(1);

		Callable<String> call = new Callable<String>() {
			public String call() throws Exception {
				// 开始执行耗时操作
				startChimpDevice1();
				return "Done";
			}
		};

		try {
			Future<String> future = exec.submit(call);
			String obj = future.get(60 * 1000 * 10, TimeUnit.MILLISECONDS);
			LOG.log(Level.WARNING, "启动成功" + obj);
		} catch (Exception e) {
			System.out.println("遍历时出现卡顿,可能是端口映射出错,重新连接");
			AndroidDebugBridge.getBridge().restart();
//			CMDUtils.runCMD1("adb kill-server", "");
//			CMDUtils.runCMD1("adb start-server", "");
			LOG.log(Level.WARNING, "启动monkey的设备失败");
			e.printStackTrace();
		}
		// 关闭线程池
		exec.shutdown();
	}



你可能感兴趣的:(android,chimpchat)