为什么MonkeyRunner.waitForConnection()在我的环境中不起作用?

job*_*ang 3 android android-emulator monkeyrunner

脚本:

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

在它运行之前:

~/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
Run Code Online (Sandbox Code Playgroud)

monkeyrunner的输出:

~/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'
Run Code Online (Sandbox Code Playgroud)

......

运行后:

~/android-sdk-linux_86/tools$adb devices
adb server is out of date.  killing...
* daemon started successfully *
List of devices attached 
Run Code Online (Sandbox Code Playgroud)

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

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

~/android-sdk-linux_86/tools$adb devices
List of devices attached 
emulator-5554   device
192.168.6.60:5555   device
Run Code Online (Sandbox Code Playgroud)

使用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
Run Code Online (Sandbox Code Playgroud)

使用脚本中的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"有效?

Chr*_*ton 5

adb server is out of date. killing...
Run Code Online (Sandbox Code Playgroud)

我的猜测是你的机器上有多个adb可执行文件.

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

Monkeyrunner然后使用不同版本的adb,发现您现有的服务器已过期(这意味着更旧或更新)并将其杀死.然后它启动一个不同的版本,它不知道你的tcp连接设备,因为你从来没有说过它(它可能不是支持tcp的版本).

这会失败,因为没有设备

之后,你检查,发现adb服务器过时,杀了它,启动它,仍然找不到设备......

尝试查找/ -name"adb"

然后在每个上运行adb版本

不要盲目地删除它们,重命名它,直到你确定你使用的是有效的.