RobolectricTestRunner::class
in my unit tests is throwing IllegalArgumentException
with no message with this stack-trace:
My unit test class:
@RunWith(RobolectricTestRunner::class)
class UnitTest {
@Test
fun testEncodeDecode() {
}
}
The output stacktrace:
java.lang.IllegalArgumentException
at org.objectweb.asm.AnnotationVisitor.<init>(Unknown Source)
at org.objectweb.asm.AnnotationVisitor.<init>(Unknown Source)
at org.objectweb.asm.tree.AnnotationNode.<init>(AnnotationNode.java:77)
at org.objectweb.asm.tree.AnnotationNode.<init>(AnnotationNode.java:63)
at org.objectweb.asm.tree.ClassNode.visitAnnotation(ClassNode.java:208)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.robolectric.internal.bytecode.ClassInstrumentor.analyzeClass(ClassInstrumentor.java:63)
at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$maybeInstrumentClass$1(SandboxClassLoader.java:121)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:50)
at org.robolectric.internal.bytecode.SandboxClassLoader.maybeInstrumentClass(SandboxClassLoader.java:120)
at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$findClass$0(SandboxClassLoader.java:111)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:50)
at org.robolectric.internal.bytecode.SandboxClassLoader.findClass(SandboxClassLoader.java:110)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.robolectric.RobolectricTestRunner.getHooksInterface(RobolectricTestRunner.java:551)
at org.robolectric.RobolectricTestRunner.configureSandbox(RobolectricTestRunner.java:235)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:230)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Going through the classes AnnotationNode
and AnnotationVisitor
I noticed that there is a api
argument passed to the super(api)
of AnnotationVisitor
which was supposed to be one of Opcodes#ASM4
or Opcodes#ASM5
or Opcodes#ASM6
or Opcodes#ASM7
but the constructor was only accepting the first two.
I noticed that there are two dependencies of org.ow2.asm:asm
with two different versions org.ow2.asm:asm:7.0
and org.ow2.asm:asm:5.0.4
which was the source of problem.
To resolve the issue you must force the Gradle to import only the 7.0 version like this:
android {
allprojects {
configurations {
all {
resolutionStrategy {
force "org.ow2.asm:asm:7.0"
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With