I am creating an application for Gingerbread and minSdkVersion=10 and targetSdkVersion=17 in my AndroidManifest.xml.
I know that I have to check if the API is supported before I call it, for example:
private void removeRule(RelativeLayout.LayoutParams params, int rule) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // API 17 params.removeRule(rule); } else { params.addRule(rule, 0); } }
But sometimes I forget / donβt know what I call the higher-level API and sometimes I wrap my program with a NoSuchMethodError exception.
Therefore, before publishing my application, I always set my project to use the Android SDK 2.3.3 and make sure that I do not make illegal method calls (for example, all the errors that I get are wrapped in an if that checks the android SDK), then install the SDK back to 4.2.2.
Is there a better way to make sure that an unsupported API is not called without switching the SDK?
(PS I am using IntelliJ)
android intellij-idea lint
Ray zhou
source share