-1

Hy,

I have some basic doubts about developing with android studio:

  • minSdkVersion 15: with this configuration I am forcing to use only the features from api level 15 and not higher. Is correct? For what I read I dont think so

  • minSdkVersion 15 and compileSdkVersion 24: with this configuration I can use api level until level 24. Is this correct?

  • minSdkVersion 15 and compileSdkVersion 23: with this configuration if I use api features from api 23, this application wont work in an android device with api level 20 for example, right?

  • With the previous configuration, and android device with api level 20 will be able to download and install the application because its api is higher than the minSdkVersion 15 but will not be able to run because it has features from api 23, right?

  • If I want to make sure that I want to use an api level and not higher because of the previous problems commented, the configuration minSdkVersion 15 and compileSdkVersion 15 is the only way? is a common practice?

Thanks a lot!

fernando1979
  • 1,727
  • 2
  • 20
  • 26

1 Answers1

1

minSdkVersion 15: with this configuration I am forcing to use only the features from api level 15 and not higher. Is correct?

No. A minSdkVersion of 15 means that you do not want your app to run on devices with a lower API level than that. 15 corresponds to Android 4.0.3.

minSdkVersion 15 and compileSdkVersion 24: with this configuration I can use api level until level 24. Is this correct?

Your IDE will allow you to write code using classes, methods, fields, etc. from API Level 24. Your IDE should also warn you that using classes, methods, fields, etc. that were added to the SDK after API Level 15 may result in runtime errors.

minSdkVersion 15 and compileSdkVersion 23: with this configuration if I use api features from api 23, this application wont work in an android device with api level 20 for example, right?

Well, API Level 20 is a special Android version for the first-generation Android Wear devices. But if we switch that to API Level 19 (Android 4.4), if you blindly call an Android 5.1 (API Level 23) method, you will crash on Android 4.4. This is why the IDE will warn you about this, why you often see checks of BuildConfig.VERSION.SDK_INT, and why the SDK has these ...Compat classes (which try to hide a lot of these version differences).

With the previous configuration, and android device with api level 20 will be able to download and install the application because its api is higher than the minSdkVersion 15 but will not be able to run because it has features from api 23, right?

The device will attempt to run the app. How far it gets depends on how well the app is written. Again, you can create an app that uses newer-API features that gracefully degrades to run on older devices. This is not significantly different than how a Web site or Web app might want to use the latest HTML5 features but gracefully degrades to handle older or less-capable browsers.

If I want to make sure that I want to use an api level and not higher because of the previous problems commented, the configuration minSdkVersion 15 and compileSdkVersion 15 is the only way?

No. Again, the IDE will (usually) yell at you when you try using SDK features that are acceptable for the compileSdkVersion but are newer than the minSdkVersion.

is a common practice?

Not since 2010 or so.

FWIW, here is the documentation on this subject, limited as it may be.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So, for what I understood if you make checkings about the android version the application is running on, you can write code higher that api 15 and if not you dont apply this code but if you dont write these checkings and use and api level higher that the android version, the application is going to crush 100% sure, right? – fernando1979 Oct 13 '16 at 21:20
  • @user3254515: If you execute code that depends on a higher version of Android than the device is running, you will crash for sure. – CommonsWare Oct 13 '16 at 21:25
  • Ok, understood. But if I want to have a clean code and not full of checkings about the android version the application is running on, maybe is not so bad to have minSdkVersion== compileSdkVersion – fernando1979 Oct 16 '16 at 16:00
  • @user3254515: That makes sense if you are the only user of your app. Otherwise, bear in mind that your users do not care whether you have "clean code" or not. They *do* care that your app does what *they* want it to do. For users of newer devices, they may expect that your app takes advantage of features from newer versions of Android. However, your "minSdkVersion== compileSdkVersion " approach means that the only way you can support those newer features is to only support newer devices. That, in turn, limits the number of possible users of your app. – CommonsWare Oct 16 '16 at 16:23
  • Of course, thanks. But developing an app the other day and selecting as minimun sdk level 15, it said: "Lower api levels target more devices but have fewer features available". So as you said the minimun level selected doesnt really limit you to use newer api so always checking the version to avoid crushing. Why doest android studio say it then? – fernando1979 Oct 19 '16 at 21:19
  • @user3254515: That is just awkward phrasing on the part of Android Studio, perhaps to try to limit the size of the message. I would argue that it should be "Lower API levels target more devices, but those older devices have fewer features available". – CommonsWare Oct 19 '16 at 21:21