0

I am working with a large project, which has a minimum API level:16. however, I came across API usages that are above API level 16.

Is there any tool in Android studio or elsewhere, other than testing with a device, to check if the code doesn't violate the minimum required API level or better point it out like an error etc.?

Thank you.

rgv
  • 1,186
  • 1
  • 17
  • 39

2 Answers2

1

The IDE will use the minimum android SDK, thus you will not get compile errors. If you there are classes in SDK 14 which are moved in sdk 16, yet you are using the imports from SDK 14, it will give a standard compile error.

So no, not that I am aware of.

engineercoding
  • 832
  • 6
  • 14
  • That is kind of the issue. I have code from API 19 and 20 etc, but minimum API is 16. But, I didn't get any compiler errors. So, no systematic way to find out if such code is used elsewhere ? – rgv Mar 15 '15 at 02:06
  • There possibly could be a warning about it, but that is not guaranteed. You should have written some code to check the current sdk and if >= execute that function. You now have the consequences of that bad habit and have to go through each file and check for it. However, there could be a tool out there, but it is not an obvious one (a quick Google search doesn't reveal much) – engineercoding Mar 15 '15 at 02:15
  • Yes, that's a bad practice used int he project. I just came to the project during the debugging phase and I found a few such pieces of code I knew were of higher API. I don't know if there are any others (probably, yes). Thats why I thought I should ask around. Appreciate the input. – rgv Mar 16 '15 at 02:51
0

You can use something like this:

public static boolean supports(final int version) {
    return Build.VERSION.SDK_INT >= version;
}

Like this,

    if (supports(Build.VERSION_CODES.HONEYCOMB)) {
         // do something HONEYCOMB+ compatible here 
    }

More codes here, http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

petey
  • 16,914
  • 6
  • 65
  • 97
  • Where would you suggest that I add this code? I am working on code that some other person built and there are nearly around hundred classes. should I make this a static method and call in every class? – rgv Mar 16 '15 at 02:55