Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between targetSdkVersion and Project build target

Tags:

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: http://developer.android.com/guide/appendix/api-levels.html

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?

like image 733
hnviet Avatar asked Aug 27 '11 15:08

hnviet


People also ask

What is the difference between compileSdkVersion and targetSdkVersion?

targetSdkVersion cannot be higher than the compileSdkVersion simply because we cannot target things that we know nothing about during compilation. Ideally, the compileSdkVersion and targetSdkVersion should be equal and both point to the latest SDK.

What is the difference between minSdkVersion and targetSdkVersion?

android:minSdkVersion — Specifies the minimum API Level on which the application is able to run. The default value is "1". android:targetSdkVersion — Specifies the API Level on which the application is designed to run.

What is the difference between compile SDK and target SDK in Android?

compileSdkVersion is the version of the compiler used in building the app, while targetSdkVersion is the "API level that the application targets".

What is Android Target version?

The Target Android Version (also known as targetSdkVersion ) is the API level of the Android device where the app expects to run. Android uses this setting to determine whether to enable any compatibility behaviors – this ensures that your app continues to work the way you expect.


2 Answers

The 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.

like image 190
Trevor Johns Avatar answered Oct 09 '22 18:10

Trevor Johns


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.

android:targetSdkVersion

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:

http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

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

http://android-developers.blogspot.com/2010/07/how-to-have-your-cupcake-and-eat-it-too.html

like image 20
hooked82 Avatar answered Oct 09 '22 16:10

hooked82