VerifyError deploying on API 1.6 VerifyError deploying on API 1.6 android android

VerifyError deploying on API 1.6


When Dalvik compiles your class/function from bytecode into native machine code, it compiles all statements, even those that are inside if conditions. On Android 1.6 virtual machine tries to resolve (verify) getActionBar function, and since there is no such function, Dalvik throws VerifyError.

You can do next trick:

class ActionBarHelper{   void setBackground(){      getActionBar().setBackgroundDrawable(...);   }}...if(android.os.Build.VERSION.SDK_INT >= 11) {   new ActionBarHelper().setBackground();    }

This way ActioBarHelper class will only be compiled/verified when you're running on SDK 11+. This will in turn allow calling getActionBar function without using reflection (reflection is another possible solution to this problem).