【问题标题】:How can I reboot Android Emulator using monkeyrunner?如何使用 monkeyrunner 重新启动 Android 模拟器?
【发布时间】:2011-02-11 08:21:11
【问题描述】:

这个脚本有什么问题?

# 导入本程序使用的monkeyrunner模块
 from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
#连接当前设备,返回一个MonkeyDevice对象
device = MonkeyRunner.waitForConnection() 
#重启
device.reboot('None')

我也尝试更改 bootloadType。我尝试使用的最后一行是 device.reboot('bootloader') 和 device.reboot('recovery'),但它也不起作用。

【问题讨论】:

    标签: android android-emulator monkeyrunner


    【解决方案1】:

    Android 开发者here 发布的内容如下:

    “重启”实际上是一个硬件 重新启动,而“停止”/“开始”是 软件重启。

    理想情况下,你应该能够使用模拟器:

    device.shell('stop');
    device.shell('start');
    

    ...但是有一个针对模拟器 >= 2.2 的启动/停止的错误 here。

    就我个人而言,我使用了一个讨厌的小 shell 脚本来杀死所有模拟器实例,然后再次启动模拟器:

    #!/bin/bash
    
    pgrep -x "emulator" > /dev/null
    until [  $? -eq 1 ]; do
      kill `pgrep -x "emulator" | cut -c 1-6`
      sleep 2
      pgrep -x "emulator"
    done
    
    # start emulator normally...
    exit 0
    

    这个脚本可以通过传入一个特定模拟器的序列号来进行精炼(可以使用“adb get-serialno”获取序列号)

    我很想看看其他人的想法/他们正在自动重启模拟器的方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2011-11-16
      • 2020-12-24
      • 2012-03-03
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多