3

脚本:

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection(5,'192.168.6.60:5555')
device.installPackage('Douban_Radio.apk')

在它运行之前:

~/android-sdk-linux_86/tools$adb connect 192.168.6.60:5555
connected to 192.168.6.60:5555
~/android-sdk-linux_86/tools$adb devices
List of devices attached 
192.168.6.60:5555   device

猴子跑步者的输出:

~/android-sdk-linux_86/tools$./monkeyrunner monkeyrunnerTest.py 
110412 18:12:35.017:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
110412 18:12:35.017:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
  File "/home/jobsyang/android-sdk-linux_86/tools/monkeyrunnerTest.py", line 6, in <module>
    device.installPackage('Douban_Radio.apk')
AttributeError: 'NoneType' object has no attribute 'installPackage'

……

运行后:

~/android-sdk-linux_86/tools$adb devices
adb server is out of date.  killing...
* daemon started successfully *
List of devices attached 

我只是不知道为什么 MonkeyRunner.waitForConnection 不起作用并终止与设备的 adb 连接?请帮助我,非常感谢!

我在本地环境中启动了一个 AVD,连接的设备是:

~/android-sdk-linux_86/tools$adb devices
List of devices attached 
emulator-5554   device
192.168.6.60:5555   device

使用 adb 命令是正确的:

~/android-sdk-linux_86/tools$adb -s emulator-5554 install Douban_Radio.apk 
859 KB/s (287518 bytes in 0.326s)
    pkg: /data/local/tmp/Douban_Radio.apk
Success

~/android-sdk-linux_86/tools$adb -s 192.168.6.60:5555  install Douban_Radio.apk 
2108 KB/s (287518 bytes in 0.133s)
    pkg: /data/local/tmp/Douban_Radio.apk
Success

在脚本中使用 MonkeyRunner.waitForConnection

MonkeyRunner.waitForConnection(5,'emulator-5554') 有效,
但 MonkeyRunner.waitForConnection(5,'192.168.6.60:5555') 仍然无效。

PS:192.168.6.60是连接adb的真机ip。

是不是真机的serialNumber错了,为什么命令“adb -s 192.168.6.60:5555 install Douban_Radio.apk”有效?

4

2 回答 2

5
adb server is out of date. killing...

我的猜测是你的机器上有不止一个 adb 可执行文件。

当您手动连接时,您使用的是支持 tcp 的 adb 版本

Monkeyrunner 然后使用不同版本的 adb,发现您现有的服务器已过时(这意味着旧的或新的)并杀死它。然后它会启动一个不同的版本,该版本不知道您的 tcp 连接设备,因为您从未告诉过它(并且它可能不是支持 tcp 的版本)。

这失败了,因为没有设备

之后,您检查,发现 adb 服务器已过期,将其杀死,启动您的服务器,但仍然找不到任何设备...

尝试查找 / -name "adb"

然后在每个人上运行 adb version

也不要盲目删除,重命名它,直到你确定你使用的是一个有效的。

于 2011-05-02T19:19:44.877 回答
3

的第二个参数waitForConnection是设备的序列号,在模拟器的情况下是'emulator-<port>':

device = MonkeyRunner.waitForConnection(5,'emulator-5554')
于 2011-04-12T13:53:55.507 回答