As I'm importing an existing Android project into Eclipse, I am asked to select an SDK build target as part of the process.
Why do I need to enter this information?
How is this different from the android:targetSdkVersion/android:minSdkVersion
values specified in AndroidManifest.xml
?
For example, in the Google IO sample app, its AndroidManifest says android:targetSdkVersion=11
, but the README says the Eclipse project needs to target API level 13 or higher, or compile errors will occur.
Here is a description of each attribute, exactly what it controls, and how you should use it.
In
AndroidManifest.xml
:midSdkVersion
: Used by the Google Play Market. The lowest API on which you will allow your app to run. Devices running a version of Android older than this will not be allowed to install your app. Set this to the lowest version of android that your code can support (i.e. it doesn't use any API calls newer than this without paying special attention to backward compatibility). Of course, you should test on a device or emulator running this version.Google provides a dashboard giving you a breakdown of the number of people using each version, which can be useful when deciding whether it's OK to stop supporting one.
Note: If you are using any of the
android-support
libraries, you should not use an older version than indicated in the name of the support library. For example,android-support-v4.jar
will not run on versions of Android older than 4.targetSdkVersion
: Used by devices at run time. Devices use this to decide whether to run your app in a backward compatibility mode. For example, if you set this to 10 (Gingerbread) devices that run 16 (Jelly Bean) will still use the visual styling of Gingerbread for your app; e.g. it will have a title bar instead of an action bar. Set this to the newest version of Android that you want your app to look like (which you can only determine by testing it on newer versions to see if it looks good and behaves well).In
project.properties
, or set via Eclipse'sProject Build Target
setting:target
: Used by your computer at compile time. The version of Android that your app is compiled against. Trying to use API features newer than this will cause an error. You should set this to the same asminSdkVersion
unless you do special things for backward compatibility (see below), so that the compiler will prevent you from accidentally using features that don't exist on your users' older devices (causing it to crash).Note: It is possible for library projects you include to require a minimum for this value. For example,
android-support-v7-appcompat
includes .xml resource files inres/layout-v14
that require you to compile against API 14 or newer.A note on backward compatibility:
There is a case when
project.properties
should be higher thanminSdkVersion
: when you want to use newer API features, but you include special code for backward compatibility to allow it to run on older devices. In this case you will have to bumpproject.properties
up to the match the oldest API that contains all the features you use.When possible, use the Android Support Libraries to accomplish backward compatibility, because it is conventional, well tested, easy, and allows you to leave
project.properties
alone. However, sometimes the support libraries do not meet your needs, in which case you will have to use techniques such as this or theseAFAIK, the
android:minSdkVersion
and the one that the Eclipse asks you to select while setting up a project are one and the same. However, theandroid:targetSdkVersion
is where you'd want your app to target a specific sdk version of Android available in the market.For example, you might have your
android:minSdkVersion="8"
(the one that Eclipse asks you during setting up of your project) because you'd want your app to run on devices that have Froyo also (along with higher versions of Android). But you might want your app to truly target GingerBread users or HoneyComb users or ICS users.EDIT : Please do keep in mind that your
targetSdkVersion
has to be equal to or more than that of theminSdkVersion
. Otherwise, it doesn't really make much sense.android:minSdkVersion
in manifest file means that market will filter devices with lower sdk.target=android-x
in project properties file means that Eclipse will not allow use methods or classes from sdk higher than x. It will show compiler errors.You can use it like this: provide min version in manifest - depending on your app critical features. Set the same value to project properties. Then, if you want use somewhere APIs from higher SDKs - raise up value in project properties, and wrap code with check if device API can do this code:
call it a feature. eclipse is not made exclusively for android. if nobody thought of adding a automatism to use the sdk version given in the manifest, then eclipse simplely wont do it. i dont think there's much magic behind this. i think it has just not been added yet to eclipse / android plugin for eclipse features.
also, since you allways may change the sdk version stated in the manifest, it makes perfectly sense to also be flexible in eclipse (you always can change the eclipse sdk target via the properties of your project). like others posted there are times when the manifest sdk may differ from the eclipse sdk. (multi sdk-version support). using a lower then the min-sdk in manifest makes no sense of course but here gain: if nobody wrote yet a checker for the eclipse plugin that checks if what you're doing makes sense, then it simply will be possible.
Guys I done some testing on these and find below answer:
minSDKVersion - application will not run below that sdk
targatSDKVersion - application runtime environment. For ex application have latest SDK in device let say 21 but you set target sdk version 19 it means when application run in this device the runtime (themes and other UI/Classes) will be 19.
Project Build Target - When you select a project build target version it means you are apk or classes will be compiled according to selected sdk. for ex - if you select project build target 16 and try to use anotation @JavaScriptInterface it will not find because this anotation is available in above that target.
maxSDKVersion - It means application will not install on above that sdk.
Every android versions are assigned to the android:targetSdkVersion. The higher version of project cannot run on a lower version of emulator but the viceversa is possible. make sure your sdk is updated and try changing the project to the corresponding version