donderdag 16 oktober 2014

Robolectric + Google Play Service 5.x = java.lang.VerifyError

When I upgraded my application recently to include Play Services 5.x (for Wearable integration) I ran into the infamous VerifyError.

Thanks to this Google post, I could easily fix the issue.

In short, when you have this in your build file:
...
    //keep GMS play services at 4.4, 5.x only works with support-v4:21.+
    //compile 'com.google.android.gms:play-services:4.4.52'
    compile 'com.google.android.gms:play-services-wearable:5.0.77'

    compile 'org.bouncycastle:bcprov-jdk16:1.46'
...

Make sure to include:
tasks.whenTaskAdded { theTask ->
    def taskName = theTask.name.toString()
    //map "testLocalDebug" to your taskName!!
    if ("testLocalDebug".toString().equals(taskName)) {
        /**
         * Listen for when robolectric adds the 'testDebug' task and when it does, add the -noverify
         * option to that task's jvmArgs.  This allows us to turn off byte code verification when
         * running our unit tests.
         */
        theTask.jvmArgs('-noverify')
    }
}

To avoid:
java.lang.VerifyError: Expecting a stackmap frame at branch target 69
Exception Details:
  Location:
    com/google/android/gms/gcm/GoogleCloudMessaging.()V @31: goto
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: b801 b54c 2ab7 011d 2ab6 0120 1301 2203
    0000010: 1202 b801 284d 2cc7 000b 2b10 2c04 54a7
...


Geen opmerkingen:

Een reactie plaatsen