
I moved the Utils.hasApi to the protected method in Compatibility. It was misleading having it in Utils, because it is not as simple as putting a "if(Utils.hasApi(11)) callApi_11_method()" there. The problem isn't when the method is executed during runtime, it is when the class is loaded into the VM using the classloader. At that point, it tries to verify that indeed every method you call from your class exists, so the conditional check doesn't work, hence VerifyError's and breakage. The appropriate way to do it is the same way as the Android support library does it. The goal is to have an interface which only one implementation is every loaded at runtime. Any implementations for versions that your device doesn't support will never get loaded, so no VerifyErrors. If you have the support library installed in your Android SDK, check out extras/android/support/v4/src/java/android/support/v4/view/MenuItemCompat.java to see how the pattern works.
Description
Languages
Java
98.5%
Shell
0.6%
Python
0.6%
AIDL
0.2%
HTML
0.1%