3

I need features from Android API-level 11 but if I set targetSdkVersion to 10 then I get the old-style menus that I want (with the menu button). Are these values "legal" to set, or does targetSdkVersion have to be higher or equal to minSdkVersion?

(Note: It seems to work!)

JohnyTex
  • 3,323
  • 5
  • 29
  • 52
  • 1
    `minSdkVersion` sets the minimum compatibility API Level, while `targetSdkVersion` sets the "compile with" API Level. Mi suggestion is to use as minimumSdkVersion the same or lower version than the targetSdkVersion. Add the support library, if required. – Phantômaxx Aug 11 '15 at 07:43

2 Answers2

4

As the document says about the android:targetSdkVersion,

An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion. This attribute 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. The application is still able to run on older versions (down to minSdkVersion).

In anycase,targetSdkVersion should always be greater than or equal to the minSdkVersion, because in no way can your app run below minSdkVersion. If you have put targetSdkVersion less than the minSdkVersion that means you are telling the android system that you have tested this app on the targetSdkVersion, but this is not possible (since your app can run on devices only as low as minSdkVersion).

Hence by contradiction targetSdkVersion should always be greater than equal to the minSdkVersion.

Antrromet
  • 15,294
  • 10
  • 60
  • 75
  • 1
    But I have set targetSdkVersion=10 and minSdkVersion=11 and it works. I believe that I can't install it on 10, but I can run it as 10 on sdk>=11. – JohnyTex Aug 11 '15 at 15:09
  • 1
    What if I'd like to disable security limitations imposed when the target SDK is >= to some value...? I could set it to 1 and have the minimum as what it must be. Would any errors arise somewhere? Or nothing will complain about it? (Note: I know Play Store doesn't allow target SDK below some values, but it would be a release outside Play Store) – Edw590 May 15 '21 at 15:24
0

Always make the targetSdkVersion greater than equal to the minSdkVersion.

You can bypass the android:targetSdkVersion version and use feature for a specific API level. Best way to solve the issue would be programatically determine the device version at runtime and go for the API specific implementation rather than specifying a hard coded value.

See here,

  // Make sure we're running on Honeycomb or higher
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // set the new menu styles
    } else {
      // do nothing and it will show the default theme
}

Check the official documentation here,

http://developer.android.com/training/basics/supporting-devices/platforms.html#version-codes

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50