Guide to running monkeyrunner

Soon Sam Santos
Sep 18, 2018 · 2 min read

In the past days I needed to run monkeyrunner to control my own device. This is useful to find memory leaks in your app, you can write a script to make multiple tasks in your phone very fast and this can cause LeakCanary to find a memory leak.

However, running monkeyrunner was a bit tough because I found a lot of problems before running it successfully.

Here are the steps you need to do to run monkeyrunner.


  1. Android Studio.
  2. SDK Tools.

Running MonkeyRunner

Go to the path where your sdk tools are. Usually it is:


Go to the bin folder


And then you will see a file there named monkeyrunner.bat.

  1. Open a command prompt.
  2. Move to your sdk tools path in the bin folder. For example, type cd C:\Users\username\AppData\Local\Android\Sdk\tools\bin and press enter.
  3. Type monkeyrunner.bat and press enter.

If your monkeyrunner is working, it should appear the following message

Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_181

However, if it is not working, as mine wasn’t, it’ll display the following error message.

SWT folder '..\framework\x86' does not exist. 
Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.

How to fix this issue?

To fix this issue go to your monkeyrunner.bat

  1. Right click on it and click on Edit;
  2. Modify this part of the code as below:
for /f %%a in ("%APP_HOME%\lib\monkeyrunner-26.0.0-dev.jar") do set jarfile=%%~nxa
set frameworkdir=.
set libdir=
rem if exist %frameworkdir%\%jarfile% goto JarFileOk
rem set frameworkdir=lib
rem if exist %frameworkdir%\%jarfile% goto JarFileOk
rem set frameworkdir=..\framework
rem add thisset frameworkdir=..\lib:JarFileOk

The first four lines are the same, it is just to localize where you are. Then you comment (using rem) the next four lines and finally you add set frameworkdir=…\lib

3. Save the file and close it;

4. Close cmd and re-open it (don’t forget to move to cd C:\…\Sdk\tools\bin);

5. Type monkeyrunner.bat again and you will find another error about adb not found;

6. Go to your tools folder;


7. Create a folder named framework;


8. Go to


9. Copy adb.exe file and paste in the framework folder you’ve just created.

10. Close cmd and re-open and type monkeyrunner.bat and you should get the following successfully message. (Don’t forget that before you type monkeyrunner.bat you should move to bin folder -> cd C:\…\Sdk\tools\bin).

Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:54:35)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_181

This solution was taken from a stackoverflow answer from ohbo, which was taken from a chinese article.

Creating a ANDROID_SWT environment variable did not work for me because it kept generating new problems. You can find another solutions in stackoverflow that may be helpful if this one did not work. Happy coding!

Soon Sam Santos

Written by

Flutter and Delphi Developer at Green. Teacher at SoonClass

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade