Skip to content

Instantly share code, notes, and snippets.

@suarezjulian
Created June 3, 2015 14:44
Show Gist options
  • Save suarezjulian/3f1e58296d4db6de2992 to your computer and use it in GitHub Desktop.
Save suarezjulian/3f1e58296d4db6de2992 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<issues format="4" by="lint 24.3">
<issue
id="NewApi"
severity="Error"
message="Call requires API level 16 (current min is 14): `android.view.ViewTreeObserver#removeOnGlobalLayoutListener`"
category="Correctness"
priority="6"
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=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
quickfix="studio,adt">
<location
file="C:\Users\j.suarez\Documents\GitHub\LintIssue\app\src\main\java\co\juliansuarez\lintissue\MainActivity.java"
line="22"
column="36"/>
</issue>
<issue
id="OldTargetApi"
severity="Warning"
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."
category="Correctness"
priority="6"
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: http://developer.android.com/reference/android/os/Build.VERSION_CODES.html"
url="http://developer.android.com/reference/android/os/Build.VERSION_CODES.html"
urls="http://developer.android.com/reference/android/os/Build.VERSION_CODES.html"
errorLine1=" targetSdkVersion 21
"
errorLine2=" ~~~~~~~~~~~~~~~~~~~"
quickfix="studio">
<location
file="C:\Users\j.suarez\Documents\GitHub\LintIssue\app\build.gradle"
line="10"
column="9"/>
</issue>
</issues>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment