Recent Changes‎ > ‎

New Lint Rules

posted Mar 14, 2012, 2:55 PM by Tor Norbye   [ updated Mar 14, 2012, 3:17 PM ]
ADT 17 adds around many new checks, looking for bugs, performance problems, security errors, usability issues, etc.  We've already described the API Check and some of the new performance checks.

Here's a brief summary of the others:
  • Find invalid @id references (where for example a RelativeLayout references an id that does not exist anywhere). If no match is found, it looks for spelling mistakes and suggests other similar ids in the error message.
  • Find incorrect casts in Java code where the cast is incompatible with the view type declared in XML layouts.
  • Find calls to setColor methods which pass the resource id for the color (R.color.blue) instead of a resolved color (getResources().getColor(R.color.blue)).
  • Find errors in format strings. This includes inconsistencies between translated versions, as well as incompatible types declared in XML and supplied in the String.format call in Java.
  • Check for deprecated XML attributes
  • Finds activities, services and content providers that are present in the code but not registered in the manifest
  • Finds onClick attribute references that do not correspond to an existing method handler
  • Find typos in XML namespace declarations, as well as unused custom namespace declarations, and ensure that custom namespaces in library projects use the new auto-namespace.
  • Find manifest files which declare more than one <uses-sdk>elements, or which fail to declare minSdkVersion or targetSdkVersion
  • Check dialog button order such that OK/Cancel are in the right order (depending on the target version of Android), that they are using the standard case ("OK", not "Ok" or "ok" etc), and that there aren't any Back buttons.
  • Check menus to ensure that they are using "ifRoom" instead of "always" for the showAsAction attribute (unless it's used sparingly)
  • Find hardcoded android:debuggable attributes on <application> elements. This can lead to accidentally leaving debug information in published applications.
  • Find hardcoded references to "/sdcard" in Java code; these should be using Environment.getExternalStorageDirectory().getPath() instead
  • Find "import android.R" statements in Java code, which can lead to confusing compilation error messages
  • Find Java code which creates world-writeable files (which can lead to security problems)
  • Find references to private resources (which can lead to runtime errors on devices that do not provide the resource, since private resources may disappear any time, and may not be present on all platforms.)
  • Finds method calls to java.lang.Math where a float variable is cast to a double and/or the return value is cast to a float, and suggests replacing it with the equivalent android.util.FloatMath method.
  • Finds calls to a getter on the same class where a field could be accessed instead.
  • Find XML files using a different encoding format than UTF-8, since this can lead to subtle bugs (and lint was fixed to properly use the specified encoding)
  • Find XML resource files that contain text which should not be there (such as in layouts). This can identify accidentally malformed documents which happen to be valid XML, such as a missing "<" tag opening character.
  • Find style references which lead to cycles, such as extending self.
  • Check for usages of edit-centric attributes on a <TextView>
Comments