Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<?xml version="1.0" encoding="UTF-8"?>
<issues format="4" by="lint 24.3">
message="Call requires API level 16 (current min is 14): `android.view.ViewTreeObserver#removeOnGlobalLayoutListener`"
summary="Calling new methods on older versions"
explanation="This check scans through all the Android API calls in the application and warns about any calls that are not available on *all* versions targeted by this application (according to its minimum SDK attribute in the manifest).
If you really want to use this API and don&apos;t need to support older devices just set the `minSdkVersion` in your `build.gradle` or `AndroidManifest.xml` files.
If your code is *deliberately* accessing newer APIs, and you have ensured (e.g. with conditional execution) that this code will only ever be called on a supported platform, then you can annotate your class or method with the `@TargetApi` annotation specifying the local minimum SDK to apply, such as `@TargetApi(11)`, such that this check considers 11 rather than your manifest file&apos;s minimum SDK as the required API level.
If you are deliberately setting `android:` attributes in style definitions, make sure you place this in a `values-vNN` folder in order to avoid running into runtime conflicts on certain devices where manufacturers have added custom attributes whose ids conflict with the new ones on later platforms.
Similarly, you can use tools:targetApi=&quot;11&quot; in an XML file to indicate that the element will only be inflated in an adequate context."
errorLine1=" text.getViewTreeObserver().removeOnGlobalLayoutListener(null);
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
message="Not targeting the latest versions of Android; compatibility modes apply. Consider testing and updating this version. Consult the android.os.Build.VERSION_CODES javadoc for details."
summary="Target SDK attribute is not targeting latest version"
explanation="When your application runs on a version of Android that is more recent than your `targetSdkVersion` specifies that it has been tested with, various compatibility modes kick in. This ensures that your application continues to work, but it may look out of place. For example, if the `targetSdkVersion` is less than 14, your app may get an option button in the UI.
To fix this issue, set the `targetSdkVersion` to the highest available value. Then test your app to make sure everything works correctly. You may want to consult the compatibility notes to see what changes apply to each version you are adding support for:"
errorLine1=" targetSdkVersion 21
errorLine2=" ~~~~~~~~~~~~~~~~~~~"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment