Why is MonkeyRunner failing with Bad type on operand error?

295 Views Asked by At

On Ubuntu 18.04, I installed MonkeyRunner via sudo apt install monkeyrunner, and it completed successfully.

I created a file called test.py and wrote the content

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

I connected my phone over USB, enabled USB debugging, then executed the program with monkeyrunner test.py but I get this error

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    com/android/monkeyrunner/ScriptRunner.console(Ljava/lang/String;)V @13: invokevirtual
  Reason:
    Type 'org/python/util/JLineConsole' (current frame, stack[0]) is not assignable to 'org/python/util/InteractiveConsole'
  Current Frame:
    bci: @13
    flags: { }
    locals: { 'java/lang/String', 'org/python/util/JLineConsole' }
    stack: { 'org/python/util/JLineConsole' }
  Bytecode:
    0x0000000: 2ab8 0035 bb00 5159 b700 524c 2bb6 0053
    0x0000010: b1                                     

    at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:73)
    at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:189)

What is causing this, and how can I resolve this?

1

There are 1 best solutions below

1
0v3rl04d On

Install Android studio with this command:

sudo snap install android-studio --classic

After that you can find "monkeyrunner" at this path:

~/Android/Sdk/tools/bin