user3254515 user3254515 - 1 month ago 6
Android Question

Newbie in Android: minSdkVersion vs compileSdkVersion

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!

Answer

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.