Suppressing Android Lint Errors

Learn how to suppress lint errors when building apps with the Brightcove Native SDK for Android.

Overview

When building Android applications with the Brightcove Native SDK, you may encounter lint errors during the build process. These errors can sometimes be overly strict or not applicable to your specific use case. This guide explains how to suppress lint errors when necessary.

Common lint errors

NotificationPermission error

When targeting Android 13 (API level 33) or higher, you might encounter this error:

Error: When targeting Android 13 or higher, posting a permission requires holding 
the POST_NOTIFICATIONS permission (usage from com.squareup.picasso.RemoteViewsAction.NotificationAction) 
[NotificationPermission]

This error occurs because the Brightcove SDK uses the Picasso library internally for image loading, which includes notification-related functionality. If your app doesn't use notifications from the SDK, you can safely suppress this error.

Suppressing lint errors

Method 1: Using lint.xml file (Recommended)

The most straightforward way to suppress lint errors is by creating a lint.xml file in your Android app module directory.

  1. Create a file named lint.xml in your app module's root directory (typically app/lint.xml)
  2. Add the following content to suppress specific lint errors:
    <lint>
        <issue id="NotificationPermission" severity="ignore" />
    </lint>

You can suppress multiple lint errors by adding more <issue> elements:

<lint>
    <issue id="NotificationPermission" severity="ignore" />
    <issue id="AnotherLintError" severity="ignore" />
</lint>

Method 2: Using gradle configuration

You can also suppress lint errors in your build.gradle file:

android {
    lintOptions {
        disable 'NotificationPermission'
        // Or to treat as warning instead of error:
        // warning 'NotificationPermission'
    }
}

For Android Gradle Plugin 7.0 and above, use:

android {
    lint {
        disable 'NotificationPermission'
        // Or to treat as warning instead of error:
        // warning 'NotificationPermission'
    }
}

Method 3: Suppressing in code

For specific code locations, you can use the @SuppressLint annotation:

@SuppressLint("NotificationPermission")
public void someMethod() {
    // Your code here
}

Best practices

  1. Understand the error: Before suppressing any lint error, make sure you understand why it's occurring and the potential consequences of ignoring it.
  2. Use the most specific suppression: If possible, suppress errors at the most specific level (code > module > project).
  3. Document suppressions: Add comments explaining why a lint error is being suppressed.
  4. Review suppressions regularly: Periodically review your lint suppressions to see if they're still necessary.

Alternative solutions

Instead of suppressing the NotificationPermission error, you could:

  1. Add the permission: If your app uses SDK notifications (like the persistent playback control notification), add the POST_NOTIFICATIONS permission to your manifest and request it at runtime.
  2. Target a lower API level: If you don't need Android 13+ features, you could target API level 32 or lower (not recommended for new apps).