@RequiresApi() and @ChecksSdkIntAtLeast() Annotations

@RequiresApi() and @ChecksSdkIntAtLeast() Annotations are used by lint tool in Android Studio to provide proper warning/error messages

Vincent Tsen
3 min readJun 24, 2023

One of the things I am confused about in Android development is these lint tool annotations. These annotations do not sound like lint tool annotations to me, but they are.

So, I call them lint tool annotations because it makes them clear to me on their purposes which provides you with the proper lint warning/error messages to you in Android Studio.

@RequiresAPI()

Let’s say you have a function that calls an Android API that requires min SDK 23, anything below 23 won’t work. You annotate @RequiresAPI(23) in your function to let the caller knows that it won't work if the Android device is running below SDK 23.

@RequiresApi(23)
fun callFunctionThatRequiresAPI23() {
/* code here only applicable for SDK API 23 and above */
}

So, you call it from another function.

fun callerFunction(){
callFunctionThatRequiresAPI23()
}

You will get this lint error if you’re running on minSdk below 23. This error message is coming from the @RequiresApi(23)

--

--

No responses yet