Question

I'm trying to use AndroidViewClient for some automation. On [github][1] there is a page about "Secure Mode". It states this:

AndroidViewClient has two possible back-ends:

  • ViewServer
  • UiAutomator

UiAutomator works on Android API 16 and higher, so if your device has a previous version your only alternative is ViewServer.

I'm trying to run dump.py, but I'm getting the "Device is secure" error. The secure mode page states that "your only alternative is ViewServer". What is viewServer and how do I use it with monkeyrunner?

I'm having a tough time grasping this because according to this image on github page, if I don't have API lvl 16 or higher, I can use the id names if I have them (which I do) I just don't know how to do it.

In summary,

I have devices at API level 15 and lower, and the source code, and I want to automate my application using viewID's. Is that possible?

LAST ERROR:

C:\Users\EGHDK\android-sdk\tools>monkeyrunner C:\AndroidViewClient-master\Andro
idViewClient-master\AndroidViewClient\examples\dump.py --ignore-secure-device --
do-not-start-view-server
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
] Script terminated due to an exception
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]Traceback (most recent call last):
  File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\e
xamples\dump.py", line 79, in <module>
    ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2).traverse
(transform=transform)
  File "C:\AndroidViewClient-master\AndroidViewClient-master\AndroidViewClient\s
rc\com\dtmilano\android\viewclient.py", line 991, in __init__
    subprocess.check_call([adb, '-s', self.serialno, 'forward', 'tcp:%d' % self.
localPort,
  File "C:\Users\EGHDK\android-sdk\tools\lib\jython.jar\Lib\subprocess.py", lin
e 469, in check_call
  File "C:\Users\EGHDK\android-sdk\tools\lib\jython.jar\Lib\subprocess.py", lin
e 456, in call
  File "C:\Users\EGHDK\android-sdk\tools\lib\jython.jar\Lib\subprocess.py", lin
e 755, in __init__
  File "C:\Users\EGHDK\android-sdk\tools\lib\jython.jar\Lib\subprocess.py", lin
e 1269, in _execute_child
OSError: Cannot run program "C:\Windows\system32\adb.exe" (in directory "C:\User
s\EGHDK\android-sdk\tools"): CreateProcess error=2, The system cannot find the
file specified

130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyException.doRaise(PyException.java:219)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.makeException(Py.java:1159)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.makeException(Py.java:1163)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.makeException(Py.java:1167)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py._execute_child$36(C:\Users\EGHDK\android-sdk\tools\lib
\jython.jar\Lib\subprocess.py:1270)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py.call_function(C:\Users\EGHDK\android-sdk\tools\lib\jyt
hon.jar\Lib\subprocess.py)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:191)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:385)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyMethod.__call__(PyMethod.java:215)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyMethod.__call__(PyMethod.java:206)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyObject.__call__(PyObject.java:367)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyObject.__call__(PyObject.java:371)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py.__init__$19(C:\Users\EGHDK\android-sdk\tools\lib\jytho
n.jar\Lib\subprocess.py:844)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py.call_function(C:\Users\EGHDK\android-sdk\tools\lib\jyt
hon.jar\Lib\subprocess.py)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:191)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:385)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyMethod.__call__(PyMethod.java:215)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyMethod.__call__(PyMethod.java:206)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyObjectDerived.dispatch__init__(PyObjectDerived.java
:1097)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyType.invoke_new_(PyType.java:444)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyType.type___call__(PyType.java:1374)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyType.__call__(PyType.java:1365)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyObject._callextra(PyObject.java:537)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py.call$7(C:\Users\EGHDK\android-sdk\tools\lib\jython.jar
\Lib\subprocess.py:456)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py.call_function(C:\Users\EGHDK\android-sdk\tools\lib\jyt
hon.jar\Lib\subprocess.py)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:370)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.function___call__(PyFunction.java:375)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:365)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyObject._callextra(PyObject.java:537)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py.check_call$8(C:\Users\EGHDK\android-sdk\tools\lib\jyth
on.jar\Lib\subprocess.py:475)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at subprocess$py.call_function(C:\Users\EGHDK\android-sdk\tools\lib\jyt
hon.jar\Lib\subprocess.py)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:124)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:317)
130425 14:05:23.047: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:995)
130425 14:05:23.047: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)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyBaseCode.call(PyBaseCode.java:191)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:385)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyFunction.__call__(PyFunction.java:380)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyInstance.__init__(PyInstance.java:120)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyClass.__call__(PyClass.java:194)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyObject._callextra(PyObject.java:537)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.pycode._pyx0.f$0(C:\AndroidViewClient-master\AndroidViewCl
ient-master\AndroidViewClient\examples\dump.py:79)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.pycode._pyx0.call_function(C:\AndroidViewClient-master\And
roidViewClient-master\AndroidViewClient\examples\dump.py)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyTableCode.call(PyTableCode.java:165)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.PyCode.call(PyCode.java:18)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.Py.runCode(Py.java:1197)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156
)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.
java:77)
130425 14:05:23.047:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions
]       at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter
.java:189)
Was it helpful?

Solution

If your device API level is < 16 your alternatives are (as depicted in this image):

  • LocalViewServer if you have access to application source code. LocalViewServer is a fork of ViewServer
  • Use the emulator (secure mode is disabled)
  • Root the device and disable secure mode yourself

LocalViewServer features LocalViewServerActivity which you can extend to simplify ViewServer implementation in your Activity.

Check the sample source code at TemperatureConverterActivity.

The reason for the error you posted seems to be:

OSError: Cannot run program "C:\Windows\system32\adb.exe" (in directory "C:\User
s\EGHDK\android-sdk\tools"): CreateProcess error=2, The system cannot find the
file specified

You should set environment variable ANDROID_HOME correctly to point to Android SDK installation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top