This time I want to use English to make this article useful for all others in the world:)
As you know, Android MonkeyRunner is a good testing tool, but we could only develop monkeyrunner under a text editor like Vim, emacs, etc.
Diego Torres Milano wrote a blog to make Monkeyrunner running on Eclipse, he had done that on Linux. But according to his article, he mislead guys thinking that his solution also works on Windows. But after serveral tries by myself and others’ comments, it does not work in Windows at all.
Here I found a solution which also works on Windows(I have tried it by myself). And I believe that it also works on Linux, as the solution does not include any platform independent mechanism. Here we go
- Install/Update latest PyDev (2.2.4 at present, I think it does not relate to the PyDev version) by Eclipse Marketplace or direct install link, see guide here
- Extract Lib folder in ANDROID_SDK\tools\lib\jython.jar using 7-Zip/WinRAR to ANDROID_SDK\tools\lib folder, which would be like ANDROID_SDK\tools\lib\Lib
- Add a Jython Interpreter under Window>Preferences>PyDev>Interpreter – Jython. Using the jython.jar from Android SDK\tools\lib folder.
- Please notice that adding Android SDK\tools\lib and monkeyrunner.jar in Libraries. See snapshot below:

- Click “Apply” and wait it finish. Press “OK”
- Now you can use this new MonkeyRunner Interpreter to set up a PyDev project. But please make sure to choose “Jython” and using Grammar version “2.5″ as Jython itself is not catching up with Python. The latest Jython is 2.5.2, but Android SDK uses 2.5.0. It’s OK to replace the old one with the latest one. That’s another story. Snapshot of project setup:

Now you could write MonkeyRunner script with convenient features like auto-completion, grammmer error notice etc. Have fun:)
Notice: you cannot click the Run button to execute monkeyrunner script, it will not use monkeyrunner.bat to execute.
请问安装的Eclipse版本是哪一版? 我用Indigo重复这些步骤,会一直出现错误
Indigo没问题呀,我就是用Indigo试的;另外建议你升级PyDev到最新版。
你确定从python.jar里面解压Lib文件夹出来了?
Hi Sean,
I used this approach and it seems to work so far. The problem is that when I try to run a script clicking the ‘run’ button in Eclipse I get NullPointerExceptions. In your post you mention we cannot use the ‘run’ in Eclipse. But I’m using Windows and I dont know other way to run this script. What do you suggest?
Regards.
Run it as the normal way to use Monkeyrunner. Plz refer to official guide of Monkeyrunner.
for example:
Thanks for the guide. I am also using Windows and was not able to get this running using DTM’s blog.
I followed your steps but I get this error when I run the file:
ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment
I’m new to Eclipse and Monkeyrunner and would appreciate any help with resolving this error.
What file? I think it’s the problem in DTM’s example file? You should ask in his post.
Dear Sir,
I ran MonkeyRunner on Win7 OS as your post, but always met the problem: ‘adb rejected adb port forwarding command cannot bind socket’.
I just installed Android SDK, python2.7, Eclipse, PyDev.
Then use the sample code in Android developer web site.
Could you show me how to fix the problem?
Many thanks.
Try command ‘adb kill-server’ and ‘adb start-server’ to restart the adb. It could be found under your android sdk directory, subfolder platform-tools.
Hi, Seganw
I tried the command, but it cannot work too. I do not know if any unknown setting in Win7 or AD problem. Still trying…
Hi Sean. I don’t know you are still watching this, but it’s worth a shot.
I did all your steps, the only difference is that the Interpreter option under Grammar version does not show MR, only default and the path to the jython.jar
I’m getting the following error: java.lang.NoClassDefFoundError: Could not initialize class com.android.monkeyrunner.MonkeyDevice
Here is my code:
from com.android.monkeyrunner import MonkeyDevice, MonkeyRunner, MonkeyImage, MonkeyManager
device= MonkeyDevice
for i in range(5):
device = MonkeyRunner.waitForConnection(8)
if device != None:
print “Device found…”
break;
device.press(“KEYCODE_NOTIFICATION”, “DOWN_AND_UP”)
time.sleep(1)
device.press(“KEYCODE_BACK”, “DOWN_AND_UP”)
do you have any thoughts?
appreciate it