Newbie in Android: minSdkVersion vs compileSdkVersion - android

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!

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.

Related

Check min version of compatibility of Android app

For an Android application, how can I test what the lowest version/API of Android it can work on, without manually changing API level on the emulator?
The minSdkVersion set in the app level gradle file is the lowest API version it will work on.
There are other factors though...for example:
Lets say the minSdkVersion is 21...but you call a method that wasnt introduced until api 25 (and dont handle that), then it will crash...and not really work.
Open build.gradle of your app there should be written minSdkVersion which it supports.

Issues executing code on higher API levels Android

My minSDK version is 16 and my targetSDK version is 27. The compileSDK version is 28.
Since the targetSDK version is 27 it should run on Oreo(8.0.0) without issues but some of the features don't work as intended. However they do work fine on Nougat.
Why is this so?
The targetSDK is stating what you built in the app to be able to handle. So, there might be a new feature in API 28 and you're saying your code was build against API 27 so if you're running on API 28 and there is support on 28 for how you used the api before, then it will try to maintain your API 27 coded behavior. There still exists the possibility your API 27 code will result in different or wrong behavior if run on API 28 though.
Please review the documentation as well:
https://developer.android.com/guide/topics/manifest/uses-sdk-element
"To maintain your application along with each Android release, you should increase the value of this attribute to match the latest API level, then thoroughly test your application on the corresponding platform version."

Does DefaultHttpClient still work running on Android 6?

Leaving target on API22 and running the app on Android 6 platform device, I see that DefaultHttpClient is still working, even though it isnt supported by the new platform.
How is it possible, does it work in a compatibility mode?
That it isn't supported does not mean it's been removed. In code you'll often see "deprecated" functions. These are functions that are not supported, but have purposefully not been removed.
In this case, you use the functionality from the Android API22 library. To preserve backwards compatibilty functionality of previous API's is almost never fully removed from the actual Android environment.
When compiling something with API level 22, the APK will actually contain parts of that library. In this case, that means that the DefaultHttpClient from API22 is actually included in your app. It doesn't use the version that is (not) on the phone. What parts are to be included in your app is decided in:
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 17
targetSdkVersion 23
}
}
Everything that is missing from API level 23 but is available in level 17 will get included in your app.

Cannot change API Level on Android Studio

I'm very new to Android development and this is one of my first projects. I realized that my API Level is set to 20 when datepicker gave an "exception rasied during rendering" error.
I wanted to change the API level to 19 as the API 20 is set to wearable devices. I have installed the API 19 SDK but it doesnt appear for selection during development.
I have also tried to set -
minSdkVersion 10
targetSdkVersion 20
on build gradle but it doesn't work.
I cannot run the emulator as the API is set to 20 and it will display error on a watch :(
How do I set make the API 19 as one of the options during development as I already installed the SDK?
Set
compileSdkVersion 19
in your build.gradle.
minSdkVersion and targetSdkVersion control app installation and runtime backwards compatibility modes, not the SDK you build with.

Android: Relationship between minSdkVersion and targetSdkVersion

I've read everything in the Google documentation that I could find regarding minSdkVersion and targetSdkVersion but I'm still not entirely sure how to use these properly.
My current application has a minSdkVersion of 8 and a targetSdkVersion also of 8, and works fine as such.
I changed my targetSdkVersion to 18 and suddenly half of my application is no longer functioning as expected. Even some simple HTTP requests were not working.
From what I understood from reading the docs, targetSdkVersion is for using features of a certain level of API, is this correct? Why were simple HTTP requests not functioning as expected when targeting 18? Are they used differently?
If someone could give a short, clean explanation on how these two attributes work, I would be very grateful.
Also, if I keep my target at 8, will it work okay on newer devices?
minSdk is the minimum api level that the device should have to be able to install your app.
In your code you can use all functions that are available since targetSdk or lower.
Example:
if your targetSdk is 14 and your minSdk is 8, and you want to use a method that is available since sdk 11, before you call the method you would have to check whether the device's sdk is 11 or higher.
If you use functions that require a higher api level than your minSdk, your code will compile but it will crash if the function is called on a device lower than targetSdk. That's why you have to check for it before you call the method or use the class.

Categories

Resources