Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27437] Android: Add @RequiresApi() annotations to core java code

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, annotations, java
ReporterJoshua Quick
AssigneeJoshua Quick
Created2019-10-02T18:57:52.000+0000
Updated2021-02-22T19:06:11.000+0000

Description

*Summary:* Google supports Java annotation @RequiresApi(number) which can be applied to classes, methods, member variables, etc. This can be used to trigger linting errors/warnings if an API was accessed on an API Level older than what was set in the annotation. https://developer.android.com/reference/android/support/annotation/RequiresApi We should leverage this feature throughout our core Titanium code to help minimize mistakes and ensure we're checking the currently running API Level before making high API Level call. This will help avoid crashes when on older Android OS versions. *Example:* The below screenshot shows this in action. A @RequiresApi(20) annotation is applied to method onApplyWindowInsets(). In the method below, we call the onApplyWindowInsets() method twice. One call is unguarded and the other call is within an if-check block which checks if we're running in API Level 20 or higher. The linting tool correctly shows a red underline for the unguarded method call. This is what we want. !RequireApiLinting.png|thumbnail! *Notes:* We should do this after switching our build system to gradle. This is because the gradle linting tool performs the API Level checks.

Attachments

FileDateSize
RequireApiLinting.png2019-10-02T18:39:09.000+0000438741

Comments

No comments

JSON Source