开发者

Why the MonkeyRunner.waitForConnection() doesn't work in my environment?

Script:

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

Before it runs:

~/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

The output of 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 attr开发者_如何学Cibute 'installPackage'

......

After it runs:

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

I just don't know why the MonkeyRunner.waitForConnection doesn't work and kills the adb connection to the device? Please help me, thanks very much!

I start up an AVD in local env, and the connected devices are:

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

Using the adb command is correct:

~/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

With the MonkeyRunner.waitForConnection in script

MonkeyRunner.waitForConnection(5,'emulator-5554') works,

but MonkeyRunner.waitForConnection(5,'192.168.6.60:5555') still not work.

PS: 192.168.6.60 is the ip of a real device connected with adb.

Is the serialNumber of the real device wrong, but why the command "adb -s 192.168.6.60:5555 install Douban_Radio.apk" works?


adb server is out of date. killing...

My guess is that you have more than one adb executable on your machine.

When you manually connect, you are using a version of adb that supports tcp

Monkeyrunner then uses a different version of adb, finds your existing server is out of date (which means either older OR newer) and kills it. It then starts a different version which doesn't know about your tcp connected device since you never told it (and it might not be a version that supports tcp).

This fails because there are no devices

Afterwards, you check, find the adb server out of date, kill it, start yours, and still find no devices...

try a find / -name "adb"

and then run adb version on each of them

Don't blindly delete either, rename it until you are sure you are using one that works.


The second parameter of waitForConnection is the device's serial number, in the case of the emulator is 'emulator-<port>':

device = MonkeyRunner.waitForConnection(5,'emulator-5554')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜