1

Following an unsuccessful Lint run, I attempted to fix an error by adding the @TargetApi(Build.VERSION_CODES.HONEYCOMB) attribute, but the next time Lint is run, the following error still shows for the getScaleX() function:

Lint NewApi error message

Can anyone shed some light on this?

CJBS
  • 15,147
  • 6
  • 86
  • 135
Hong
  • 17,643
  • 21
  • 81
  • 142
  • Related: http://stackoverflow.com/questions/12211061/targetapi-not-taken-into-account & http://stackoverflow.com/questions/14341042/what-is-better-suppresslint-or-targetapi?lq=1 – CJBS Nov 19 '14 at 00:57

1 Answers1

0

The call to getScaleX() requires API level 11 (Honeycomb), as mentioned in the message window. The message also indicates that the minimum API level is 9 (as per the minSdkVersion setting).

The Lint tool is warning you that you are using a method supported only in newer SDK versions (11+), but have set to allow the application to run on devices that don't support this method (SDK versions 9 and 10).

See a more detailed description of what the NewApi Lint check does here: (search for NewApi) http://tools.android.com/tips/lint-checks

Suppress such warnings with caution, I'd suggest protecting the code with something like this:

    if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
        ...getScaleX()...
    }
CJBS
  • 15,147
  • 6
  • 86
  • 135
  • Thanks for the answer. Unfortunately,it does not answer my question. What you proposed is exactly what I have been using. My question is about why Lint check still fails, not about failure of code. The code works perfectly on all versions of Android. – Hong Nov 19 '14 at 11:08
  • Do you have a version check around the code in question? I.e. something like `if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)`? If not, then if you're running on an earlier SDK version (on the device), then I'd expect the code to fail. – CJBS Nov 19 '14 at 17:06
  • Yes, as my first comment states, my code is exactly like your answer. Again, the code works perfectly and the app works fine. It is just that it cannot pass Lint. – Hong Nov 19 '14 at 17:17
  • Does it still happen if you tag the method with `@SuppressLint("NewApi")` (as opposed to `@TargetApi`? Or putting the `@TargetApi(Build.VERSION_CODES.HONEYCOMB)` at the top of the class definition? I have similar code (using Android Studio, not Eclipse), and when I change the @TargetApi to the version targeted , despite the `minSdkVersion` being lower, the Lint message no longer appears. – CJBS Nov 19 '14 at 19:10
  • Thanks for trying to lend a hand. I am sorry but I have to say that I have given up. The behavior of Lint check on my dev machine is erratic. At this moment, it complains about certain functions in commented out code. – Hong Nov 21 '14 at 04:32
  • Might be time to check out Android Studio :-) – CJBS Nov 21 '14 at 06:59
  • I have been thinking about Android Studio, but it is still in beta. – Hong Nov 21 '14 at 11:30