Accepted answer


an integer designating the minimum api level required for the application to run. the android system will prevent the user from installing the application if the system's api level is lower than the value specified in this attribute. you should always declare this attribute.


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.

for more information refer this url:


target sdk is the version you want to target, and min sdk is the minimum one.


if you are making apps that require dangerous permissions and set targetsdk to 23 or above you should be careful. if you do not check permissions on runtime you will get a securityexception and if you are using code inside a try block, for example open camera, it can be hard to detect error if you do not check logcat.


android:minsdkversion and android:targetsdkversion both are integer value we need to declare in android manifest file but both are having different properties.

android:minsdkversion: this is minimum required api level to run an android app. if we will install the same app on lower api version the parser error will be appear, and application not support problem will appear.

android:targetsdkversion: target sdk version is to set the target api level of app. if this attribute not declared in manifest, minsdk version will be your targetsdk version. this is always true that "app support installation on all higher version of api we declared as targetsdk version". to make app limited target we need to declare maxsdkversion in our manifest file...


if you get some compile errors for example:

            android:targetsdkversion="15" />


private void methodthatrequiresapi11() {
        bitmapfactory.options options = new bitmapfactory.options();
                options.inpreferredconfig = config.argb_8888;  // api level 1          
                options.insamplesize = 8;    // api level 1
                options.inbitmap = bitmap;   // **api level 11**

you get compile error:

field requires api level 11 (current min is 10):$options#inbitmap

since version 17 of android development tools (adt) there is one new and very useful annotation @targetapi that can fix this very easily. add it before the method that is enclosing the problematic declaration:

private void methodthatrequiresapi11() {            
  bitmapfactory.options options = new bitmapfactory.options();
      options.inpreferredconfig = config.argb_8888;  // api level 1          
      options.insamplesize = 8;    // api level 1

      // this will avoid exception nosuchfielderror (or nosuchmethoderror) at runtime. 
      if (integer.valueof( >= {
        options.inbitmap = bitmap;   // **api level 11**

no compile errors now and it will run !

edit: this will result in runtime error on api level lower than 11. on 11 or higher it will run without problems. so you must be sure you call this method on an execution path guarded by version check. targetapi just allows you to compile it but you run it on your own risk.


for those who want a summary,


is minimum version till your application supports. if your device has lower version of android , app will not install.



is the api level till which your app is designed to run. means, your phone's system don't need to use any compatibility behaviours to maintain forward compatibility because you have tested against till this api.

your app will still run on android versions higher than given targetsdkversion but android compatibility behaviour will kick in.

freebie -


if your device's api version is higher, app will not install. ie. this is the max api till which you allow your app to install.

ie. for minsdk -4, maxsdk - 8, targetsdk - 8 my app will work on minimum 1.6 but i also have used features that are supported only in 2.2 which will be visible if it is installed on a 2.2 device. also, for maxsdk - 8, this app will not install on phones using api > 8.

at the time of writing this answer, android documentation was not doing a great job at explaining it. now it is very well explained. check it here


a concept can be better delivered with examples, always. i had trouble in comprehending these concept until i dig into android framework source code, and do some experiments, even after reading all documents in android developer sites & related stackoverflow threads. i'm gonna share two examples that helped me a lot to fully understand these concepts.

a datepickerdialog will look different based on level that you put in androidmanifest.xml file's targetsdkversion(<uses-sdk android:targetsdkversion="integer_value"/>). if you set the value 10 or lower, your datepickerdialog will look like left. on the other hand, if you set the value 11 or higher, a datepickerdialog will look like right, with the very same code.

datepickerdialog look with targetsdkversion 10 or lower datepickerdialog look with targetsdkversion 11 or higher

the code that i used to create this sample is super-simple. looks :

public class mainactivity extends activity {

    protected void oncreate(bundle savedinstancestate) {

    public void onclickbutton(view v) {
        datepickerdialog d = new datepickerdialog(this, null, 2014, 5, 4);;       

and activity_main.xml looks :

<relativelayout xmlns:android=""
    android:layout_height="match_parent" >
    android:text="button" />

that's it. that's really every code that i need to test this.

and this change in look is crystal clear when you see the android framework source code. it goes like :

public datepickerdialog(context context,
    ondatesetlistener callback,
    int year,
    int monthofyear,
    int dayofmonth,
    boolean yearoptional) {
        this(context, context.getapplicationinfo().targetsdkversion >= build.version_codes.honeycomb
        callback, year, monthofyear, dayofmonth, yearoptional);

as you can see, the framework gets current targetsdkversion and set different theme. this kind of code snippet(getapplicationinfo().targetsdkversion >= some_version) can be found here and there in android framework.

another example is about webview class. webview class's public methods should be called on main thread, and if not, runtime system throws a runtimeexception, when you set targetsdkversion 18 or higher. this behavior can be clearly delivered with its source code. it's just written like that.

senforcethreadchecking = context.getapplicationinfo().targetsdkversion >=

if (senforcethreadchecking) {
    throw new runtimeexception(throwable);

the android doc says, "as android evolves with each new version, some behaviors and even appearances might change." so, we've looked behavior and appearance change, and how that change is accomplished.

in summary, the android doc says "this attribute(targetsdkversion) informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version.". this is really clear with webview case. it was ok until jelly_bean_mr2 released to call webview class's public method on not-main thread. it is nonsense if android framework throws a runtimeexception on jelly_bean_mr2 devices. it just should not enable newly introduced behaviors for its interest, which cause fatal result. so, what we have to do is to check whether everything is ok on certain targetsdkversions. we get benefit like appearance enhancement with setting higher targetsdkversion, but it comes with responsibility.

edit : disclaimer. the datepickerdialog constructor that set different themes based on current targetsdkversion(that i showed above) actually has been changed in later commit. nevertheless i used that example, because logic has not been changed, and those code snippet clearly shows targetsdkversion concept.


when you set targetsdkversion="xx", you are certifying that your app works properly (e.g., has been thoroughly and successfully tested) at api level xx.

a version of android running at an api level above xx will apply compatibility code automatically to support any features you might be relying upon that were available at or prior to api level xx, but which are now obsolete at that android version's higher level.

conversely, if you are using any features that became obsolete at or prior to level xx, compatibility code will not be automatically applied by os versions at higher api levels (that no longer include those features) to support those uses. in that situation, your own code must have special case clauses that test the api level and, if the os level detected is a higher one that no longer has the given api feature, your code must use alternate features that are available at the running os's api level.

if it fails to do this, then some interface features may simply not appear that would normally trigger events within your code, and you may be missing a critical interface feature that the user needs to trigger those events and to access their functionality (as in the example below).

as stated in other answers, you might set targetsdkversion higher than minsdkversion if you wanted to use some api features initially defined at higher api levels than your minsdkversion, and had taken steps to ensure that your code could detect and handle the absence of those features at lower levels than targetsdkversion.

in order to warn developers to specifically test for the minimum api level required to use a feature, the compiler will issue an error (not just a warning) if code contains a call to any method that was defined at a later api level than minsdkversion, even if targetsdkversion is greater than or equal to the api level at which that method was first made available. to remove this error, the compiler directive


tells the compiler that the code within the scope of that directive (which will precede either a method or a class) has been written to test for an api level of at least nn prior to calling any method that depends upon having at least that api level. for example, the following code defines a method that can be called from code within an app that has a minsdkversion of less than 11 and a targetsdkversion of 11 or higher:

    public void refreshactionbarifapi11orhigher() {
      //if the api is 11 or higher, set up the actionbar and display it
      if(build.version.sdk_int >= 11) {
        //actionbar only exists at api level 11 or higher
        actionbar actionbar = getactionbar();

        //this should cause onprepareoptionsmenu() to be called.
        // in versions of the api prior to 11, this only occurred when the user pressed 
        // the dedicated menu button, but at level 11 and above, the action bar is 
        // typically displayed continuously and so you will need to call this
        // each time the options on your menu change.

        //show the bar;

you might also want to declare a higher targetsdkversion if you had tested at that higher level and everything worked, even if you were not using any features from an api level higher than your minsdkversion. this would be just to avoid the overhead of accessing compatibility code intended to adapt from the target level down to the min level, since you would have confirmed (through testing) that no such adaptation was required.

an example of a ui feature that depends upon the declared targetsdkversion would be the three-vertical-dot menu button that appears on the status bar of apps having a targetsdkversion less than 11, when those apps are running under api 11 and higher. if your app has a targetsdkversion of 10 or below, it is assumed that your app's interface depends upon the existence of a dedicated menu button, and so the three-dot button appears to take the place of the earlier dedicated hardware and/or onscreen versions of that button (e.g., as seen in gingerbread) when the os has a higher api level for which a dedicated menu button on the device is no longer assumed. however, if you set your app's targetsdkversion to 11 or higher, it is assumed that you have taken advantage of features introduced at that level that replace the dedicated menu button (e.g., the action bar), or that you have otherwise circumvented the need to have a system menu button; consequently, the three-vertical-dot menu "compatibility button" disappears. in that case, if the user can't find a menu button, she can't press it, and that, in turn, means that your activity's oncreateoptionsmenu(menu) override might never get invoked, which, again in turn, means that a significant part of your app's functionality could be deprived of its user interface. unless, of course, you have implemented the action bar or some other alternative means for the user to access these features.

minsdkversion, by contrast, states a requirement that a device's os version have at least that api level in order to run your app. this affects which devices are able to see and download your app when it is on the google play app store (and possibly other app stores, as well). it's a way of stating that your app relies upon os (api or other) features that were established at that level, and does not have an acceptable way to deal with the absence of those features.

an example of using minsdkversion to ensure the presence of a feature that is not api-related would be to set minsdkversion to 8 in order to ensure that your app will run only on a jit-enabled version of the dalvik interpreter (since jit was introduced to the android interpreter at api level 8). since performance for a jit-enabled interpreter can be as much as five times that of one lacking that feature, if your app makes heavy use of the processor then you might want to require api level 8 or above in order to ensure adequate performance.


the comment posted by the op to the question (basically stating that the targetsdk doesn't affect the compiling of an app) is entirely wrong! sorry to be blunt.

in short, here is the purpose to declaring a different targetsdk from the minsdk: it means you are using features from a higher level sdk than your minimum, but you have ensured backwards compatibility. in other words, imagine that you want to use a feature that was only recently introduced, but that isn't critical to your application. you would then set the targetsdk to the version where this new feature was introduced and the minimum to something lower so that everyone could still use your app.

to give an example, let's say you're writing an app that makes extensive use of gesture detection. however, every command that can be recognised by a gesture can also be done by a button or from the menu. in this case, gestures are a 'cool extra' but aren't required. therefore you would set the target sdk to 7 ("eclair" when the gesturedetection library was introduced), and the minimumsdk to level 3 ("cupcake") so that even people with really old phones could use your app. all you'd have to do is make sure that your app checked the version of android it was running on before trying to use the gesture library, to avoid trying to use it if it didn't exist. (admittedly this is a dated example since hardly anyone still has a v1.5 phone, but there was a time when maintaining compatibility with v1.5 was really important.)

to give another example, you could use this if you wanted to use a feature from gingerbread or honeycomb. some people will get the updates soon, but many others, particularly with older hardware, might stay stuck with eclair until they buy a new device. this would let you use some of the cool new features, but without excluding part of your possible market.

there is a really good article from the android developer's blog about how to use this feature, and in particular, how to design the "check the feature exists before using it" code i mentioned above.

to the op: i've written this mainly for the benefit of anyone who happens to stumble upon this question in the future, as i realise your question was asked a long time ago.

Related Query

More Query from same tag