What is the difference between targetSdkVersion set in the Manifest file and the Project build target set in the building environment (e.g. Eclipse) ?
I have tried to find more information on these two features, but I couldn’t find any clear and specific explanation.
It seems like the Project build target decides on the API compatibility level, to be used during the compilation. When the targetSdkVersion only affects the visibility of the manifest elements of the given API level.
Could anyone confirm/expound this?
EDIT: Thanks guys for prompt responses. I forgot to mention in my question that I have read all the topics on Android Dev regarding these features and also googled it and searched it on Stack Overflow. So I understand the basic purpose of min/target/maxSdkVersion to be used in Android Market and in the Android System itself. However, according to other posts from people having problems with this Manifest option, it seems uses-sdk does actually have impact on how the the API level is interpreted. At least that is what I suspect.
A really good explanation is given here:
However, it is still unclear for me whether the targetSdkVersion does affect the compilation/runtime of the APK on Android System? Or it is only for validation as the uses-sdk documentation suggests?
targetSdkVersion attribute does indeed affect an application’s runtime behavior.
Depending on what you set it to will determine whether compatibility features are enabled/disabled in the Android framework.
For example, once you set targetSdkVersion=11, your application’s default theme will be set to
@android:style/Theme.Holo — meaning your application will have a Honeycomb-style UI widgets, will get an Action Bar, and will not have an Options Menu button at the bottom of the screen.
If you set targetSdkVersion to a lower value than, your default theme will continue to be
@android:style/Theme — regardless of which API level you’re actually building against.
The targetSdkLevel also affects what the default values are for the
<supports-screens> element, which in turn will determine whether your application runs in density compatibility mode.
Interesting note: Android Market doesn’t actually use the targetSdkLevel attribute for anything at the moment. It’s purely used at runtime for compatibility purposes, and possibly at compile time — though I haven’t looked into the behavior there. If people are curious about the compiler, I could check with the SDK team to get more information.
Of course, it’s entirely possible that Market could decide to do something with this in the future.
The Build Target is used to know which SDK to compile your APK with. This means that if there are any Classes or methods that aren’t available in your min SDK version, but are in versions after that, those Classes or methods will still be available to use. You will just have to make sure to check when you’re using those and do alternate approaches if the user’s SDK version isn’t compatible with those classes/methods.
An integer designating the API Level that the application is targetting.
With this attribute set, the application says that it is able to run on older versions (down to minSdkVersion), but was explicitly tested to work with the version specified here. Specifying this target version allows the platform to disable compatibility settings that are not required for the target version (which may otherwise be turned on in order to maintain forward-compatibility) or enable newer features that are not available to older applications. This does not mean that you can program different features for different versions of the platform—it simply informs the platform that you have tested against the target version and the platform should not perform any extra work to maintain forward-compatibility with the target version.
You can find more information by referring to this URL:
There’s also a good article written by google on checking to make sure you’re current users Android OS version will use the appropriate Classes/methods
In your “Create Project”-dialog in Eclipse, you specify the
minSdkVersion. This is the API-Level that is required to run your application.
targetSdkVersion-attribute only tells the Android Market that your App was developed (and maybe optimized) to run under the specified API-Level.
Build target is the one on which you will be testing the app. targetSdkVersion is the one your app was specifically developed for. Both are same most of the times.
You will find a detailed explanation here.
This question has already been adequately answered, but I want to point out that it is no longer entirely correct that the Google Play store does not use targetSdkVersion at all.
In the specific case where you set targetSdkVersion to 23 (Marshmallow 6.0) and upload your APK, even if you are uploading a Beta version, you will not be able to ever again submit an APK for that app that has a lower targetSdkVersion than 23.
This is because of changes to permissions between 22 and 23 which are not allowed to be reversed for a given app.
This can be a bit of a trap if you were just trying out 23 in Beta and not sure you were ready to support it yet.
targetSdkVersion attribute informs the system that you have tested your app against the given version (api level) and the system should not enable any compatibility behaviors to maintain your app’s forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).
For further detail – http://developer.android.com/guide/topics/manifest/uses-sdk-element.html