Robolectric: java.lang.VerifyError: Expecting a stackmap frame at branch target XX

Created on 7 Dec 2016  路  3Comments  路  Source: robolectric/robolectric

Description

Here at Leanplum, we develop an SDK for our customers. We are running our unit tests against our actual source code. Our customers however happen to run their unit tests with our compiled jar file.
When running Roboelectric unit tests with our compiled jar/aar sdk it actually fails with this error:

java.lang.VerifyError: Expecting a stackmap frame at branch target 18
Exception Details:
  Location:
    com/leanplum/Leanplum.getContext()Landroid/content/Context; @3: ifnonnull
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0x0000000: b200 c1c7 000f 04bd 009b 5903 1210 53b8
    0x0000010: 013b b200 c1b0                         


    at com.leanplum.leanplumroboelectrictest.LeanplumUnitTest.testLeanplum(LeanplumUnitTest.java:14)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    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.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    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.AppMain.main(AppMain.java:144)
Process finished with exit code 255

Interestingly when changing the Leanplum SDK version from 1.3.1 to:
compile 'com.leanplum:Leanplum:1.2.25' it works again.
Appreciate any insights!

Steps to Reproduce

git clone https://github.com/benmarten/LeanplumRoboelectricTest.git
Open Android Studio and run test class: LeanplumUnitTest

Robolectric & Android Version

robolectric:3.1.4
android: 24.4.1_1
compileSdkVersion 25
buildToolsVersion "25.0.1"
java, bundled with android studio

UPDATE ###

I did some more digging, compared the compiler java versions of both jars:

~/Downloads $ javap -verbose 1.2.25/leanplum/Leanplum.class | grep major                                             11:26:43
 major version: 51
~/Downloads $ javap -verbose 1.3.1/leanplum/Leanplum.class | grep major                                              11:26:57
 major version: 51

So they are the same, both are compiled with jdk7...

I also tried setting Android Studios JDK to my system one, (it wouldn't let me pick only jdk8, not 7):
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home

So anyone knows whats the issue here?

UPDATE2

Adding -noverify flag, doesn't help either.

Most helpful comment

Fixed it by following https://github.com/robolectric/robolectric-gradle-plugin/issues/144#issuecomment-265899560. The issue was that our lib was proguarded like an app, by using the getDefaultProguardFile method in the gradle file - removing it resolved the verification issue.

All 3 comments

Ok, i got it resolved by adding the -noverify flag with Android Studio:
https://github.com/robolectric/robolectric-gradle-plugin/issues/144#issuecomment-189561165

I would still like to know if anyone knows why this happens and how we can fix the rootcause?

Fixed it by following https://github.com/robolectric/robolectric-gradle-plugin/issues/144#issuecomment-265899560. The issue was that our lib was proguarded like an app, by using the getDefaultProguardFile method in the gradle file - removing it resolved the verification issue.

Was this page helpful?
0 / 5 - 0 ratings