I created Android test project and want to use JMOCK on it.
I include following jars to my project classpath
- amcrest-all-1.1.jar
- jmock-2.5.1.jar
- jmock-junit4-2.5.1.jar
- junit.jar
- objenesis-1.0.jar
until compiling i’ve got this error message :
[2012-07-06 17:14:40 – mockTest] Dx …at bytecode offset 0000001b
locals[0000]: Lorg/hamcrest/generator/qdox/parser/impl/JFlexLexer;
locals[0001]: I locals[0002]: [C locals[0003]: [C locals[0004]: [I
locals[0005]: [I locals[0006]: locals[0007]:
locals[0008]: locals[0009]: locals[000a]:
locals[000b]: locals[000c]:
locals[000d]: locals[000e]: locals[000f]:
locals[0010]: stack[top0]: [B …while working on
block 001b …while working on method yylex:()I …while processing
yylex ()I …while processing
org/hamcrest/generator/qdox/parser/impl/JFlexLexer.class[2012-07-06 17:14:40 – mockTest] Dx 1 error; aborting [2012-07-06
17:14:40 – mockTest] Conversion to Dalvik format failed with error 1
What is the problem? is there any incorrect jar in classpath?
The problem is that JMock works using dynamic bytecode generation, but Dalvik isn’t capable of doing that: dynamic bytecode generation is compiled down to JVM bytecode that’s not supported by Dalvik; hence the error when converting.
Unfortunately, that means you can’t use JMock on Android — if you need it for testing, you’ll have to run those tests on a JVM.