1

我一直在玩弄 AndroidViewClient 一段时间,但我不明白为什么这个扩展在运行 dump.py 示例时不会显示视图的 id。我的设备高于 API lvl 16。可能是什么问题?

我得到这样的输出,但我不知道为什么它不能告诉视图的名称......

android.widget.FrameLayout id/no_id/1
   android.widget.LinearLayout id/no_id/2
      android.widget.FrameLayout id/no_id/3
         android.widget.RelativeLayout id/no_id/4
            android.widget.Button id/no_id/5 New Jersey
            android.widget.Button id/no_id/6 New York
            android.widget.Button id/no_id/7 New Castle
            android.widget.Button id/no_id/8 New Berg
            android.widget.Button id/no_id/9 New Class

错误:

   C:\Users\EGHDK\android-sdk\tools>monkeyrunner C:\AndroidViewClient-master\Andro
idViewClient-master\AndroidViewClient\examples\dump.py
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] Script terminated due to an exception
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]Traceback (most recent call last):
  File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\e
xamples\dump.py", line 87, in <module>
    vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2)
  File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\s
rc\com\dtmilano\android\viewclient.py", line 935, in __init__
    adb = ViewClient.__obtainAdbPath()
  File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\s
rc\com\dtmilano\android\viewclient.py", line 1075, in _ViewClient__obtainAdbPath

    raise Exception('adb="%s" is not executable. Did you forget to set ANDROID_H
OME in the environment?' % adb)
Exception: adb="adb.exe" is not executable. Did you forget to set ANDROID_HOME i
n the environment?

130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyException.doRaise(PyException.java:219)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.makeException(Py.java:1159)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.makeException(Py.java:1163)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.makeException(Py.java:1167)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.dtmilano.android.viewclient$py._ViewClient__obtainAdbPath$56(C:\A
ndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\src\com\dtmil
ano\android\viewclient.py:1075)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.dtmilano.android.viewclient$py.call_function(C:\AndroidViewClient
-master\AndroidViewClient-master\AndroidViewClient\src\com\dtmilano\android\view
client.py)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:117)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:307)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.dtmilano.android.viewclient$py.__init__$54(C:\AndroidViewClient-m
aster\AndroidViewClient-master\AndroidViewClient\src\com\dtmilano\android\viewcl
ient.py:1020)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.dtmilano.android.viewclient$py.call_function(C:\AndroidViewClient
-master\AndroidViewClient-master\AndroidViewClient\src\com\dtmilano\android\view
client.py)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:191)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:385)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:380)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyInstance.__init__(PyInstance.java:120)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyClass.__call__(PyClass.java:194)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyObject._callextra(PyObject.java:537)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.pycode._pyx0.f$0(C:\AndroidViewClient-master\AndroidViewCl
ient-master\AndroidViewClient\examples\dump.py:89)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.pycode._pyx0.call_function(C:\AndroidViewClient-master\And
roidViewClient-master\AndroidViewClient\examples\dump.py)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyCode.call(PyCode.java:18)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.runCode(Py.java:1197)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156
)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.
java:77)
130428 20:11:28.636:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter
.java:189)
4

1 回答 1

3

If device's API level is >= 16 the default backend used by AndroidViewClient is UiAutomator which does not show the IDs. To provide an extra level of help AndroidViewClient assigns unique IDs to the Views, and this is what dump.py is showing in your case.

androidviewclient activity diagram

You can force ViewServer backend by providing the corresponding command line option to dump.py:

$ dmup.py --force-view-server-use

and you will get View ID's.

于 2013-04-28T06:38:33.520 回答