-1

I have 2 questions. If I compiled my app with targetSDKVersion 23 but tested it on an emulator running api level 19, will I be sure that it runs on a device with api level 19?

When I set minSDKVersion to an API level and use something that is not available on that api level will I get a compiler error? If not how can I be sure on what is the minimum api level my program is compatible with?

Andreas Oikonomou
  • 3,257
  • 2
  • 13
  • 13

1 Answers1

1

If I compiled my app with targetSDKVersion 23 but tested it on an emulator running api level 19

The targetSdkVersion won't change your code or how it's run on a device.

When I set minSDKVersion to an API level and use something that is not available on that api level will I get a compiler error?

You won't get a compiler error - you'll get a lint warning. If you actually run on a device without that API, you'll get a runtime error.

how can I be sure on what is the minimum api level

At runtime you can query the SDK level of the device:

Build.VERSION.SDK_INT will be the API level.

You can then perform checks using the constants to degrade gracefully:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    // fallback
} else {
    // use your lollipop api
}
ataulm
  • 15,195
  • 7
  • 50
  • 92
  • Sorry, I meant compileSdkVersion in Android Studio, I used 23, but the device I want it to run has 19. If it works in the emulator with api level 19 it means it will work on the device with the same api level, right? – Andreas Oikonomou Nov 29 '15 at 00:33
  • "Will work" it could fail on device for any number of reasons: all devices are different, there are different implementations of Android with different bugs to each other. Yes I would expect it to work in the general case though. – ataulm Nov 29 '15 at 12:04