VerifyError - Verifier rejected class
Asked Answered
C

1

10

I'm developing for 2.2 (minSdkVersion=8) and suddenly I'm getting this error:

arbitrarily rejecting large method (regs=75 count=28584)
rejected Lcom/Demo/Loyalty/SelectType;.onClick (Landroid/view/View;)V
Verifier rejected class Lcom/Demo/Loyalty/SelectType;
Class init failed in newInstance call (Lcom/Demo/Loyalty/SelectType;)


java.lang.VerifyError: com.Demo.Loyalty.SelectType
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

It was working fine until now.

Note : SelectType class has around 16000 lines of code but that is not that large I guess.

I search a lot on net and from answers, I did following:

  • Clean the project
  • Reset the ADB
  • Restart emulator/device/eclipse
  • Checked that third party library field is checked in build path

But I'm still getting that error.

Any help appreciated.

Chausses answered 6/2, 2013 at 11:1 Comment(0)
P
7

The steps you've described probably won't help.

The thing is, it's not a Dalvik issue. Similar verifier is employed in the Oracle Java VM for example. Simple answer: your method is too complex. The error you see is mainly caused by too many:

  • parameters
  • local variables
  • exception handlers
  • code instructions

More precisely, the issue has been described in this thread: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/4qNoIdBHYFc

To quote:

The value of (number of registers * number of instruction words) is larger than 2^21. (...) it's intended to prevent the verifier from bloating up an app's native heap.

You can also see similar report here: http://www.mentby.com/Group/android-developers/verifyerror-arbitrarily-rejecting-large-method.html with pointers on how to resolve the issue:

Yep, the Dalvik compiler attempts to assign a "register" to every local variable in the method. It should be able to handle that many, but apparently can't. By making them instance variables you remove the compiler's need/desire to "manage" them (and also make the method a fair amount smaller).

So to solve it, you should generally break the large method (probably onClick()?) into smaller pieces. Also, converting local variables to class fields seemed to help some people with the same issue.

Pazit answered 6/2, 2013 at 11:42 Comment(9)
but in my case, how do I know which method is causing arbitrarily rejecting large method (regs=75 count=28584) to occur?Chausses
the largest one :D but seriously, it's in the warning: com.Demo.Loyalty.SelectType.onClick()Pazit
its overridden method for click events. I have click event handlers for all the buttons in my activity(viewflipper) in this method. It's around 3200 lines long.Chausses
please read my answer carefully - it doesn't matter what the method does. also its length isn't the only factor involved - number of variables is of the same importance here. just break your method to a few smaller methods and you'll be fine.Pazit
Okay. But what if method method1(), say 100 lines long, is calling another method method2() which is 50 lines long. So what will be the effective lenghth of method1() ???Chausses
ah, this is your concern. the effective length will be 100 lines. so it's fairly easy - simply paste chunks of code to helper methods. the key is to lower method length and/or number of variables just in that one onClick() method. you don't have to worry about others.Pazit
Okay. Thats it. I got it. Thanks a ton buddy.Chausses
...until you hit Android's method limitZelikow
For what its' worth, using jack and java 1.8 w/ the N preview lead to this problem for me. So if you have it turned on, try turning jack off and going back to 1.7. This is with preview 1 of android studio 2.2Faircloth

© 2022 - 2024 — McMap. All rights reserved.