Using Android monkeyrunner from Eclipse, both in Windows and Linux!

Posted: November 24, 2011 in Android, Coding, MonkeyRunner, Python
Tags: , , , , , ,

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 :)

      1. 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
      2. 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
      3. Add a Jython Interpreter under Window>Preferences>PyDev>Interpreter – Jython. Using the jython.jar from Android SDK\tools\lib folder.
      4. Please notice that adding Android SDK\tools\lib and monkeyrunner.jar in Libraries. See snapshot below: Monkeyrunner in Eclipse
      5. Click “Apply” and wait it finish. Press “OK”
      6. 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.

Comments
  1. Joshua says:

    请问安装的Eclipse版本是哪一版? 我用Indigo重复这些步骤,会一直出现错误

    • fclef says:

      Indigo没问题呀,我就是用Indigo试的;另外建议你升级PyDev到最新版。
      你确定从python.jar里面解压Lib文件夹出来了?

  2. Tiago Farias says:

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s