I recently discovered a fatal error in my android app running on Android version 10 from this line:
((Button)alert.findViewById(android.R.id.button1)).setAllCaps(true);
I have set android:minSdkVersion="9"
in AndroidManifest.xml
.
The root cause was android.widget.Button inherits from android.widget.TextView and the setAllCaps method was implemented in API level 14.
Reference: https://developer.android.com/reference/android/widget/TextView.html#setAllCaps(boolean)
So my question is why can't I get lint to discover this class of error?
I would presume that lint --check NewApi .
would find this kind of issue.
Is it because the dialog which has this button is dynamically created just before this code?
Is there anything I can do to help lint prevent this class of error? In a perfect world I would like warnings to be thrown for any methods called from SDK versions higher than minSdk
.