Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-27437

Android: Add @RequiresApi() annotations to core java code

    Details

      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 that 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.

      Notes:
      We should do this after switching our build system to gradle. This is because the gradle linting tool performs the API Level checks.

      Also, the @RequireApi() annotation requires the following Google support library...
      com.android.support:support-annotations

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
              • Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Source Code