脚本:
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”有效?