Search code examples
androidtarget-sdk

old targetSdkVersion for new devices


I have a very old android app. I used minSdkVersion 18 and targetSdkVersion 21. Now it is Android v26 and there are still many users using v24. If the user is using Android v24 or above, can they run my app as my targetSdkVersion is 21. If yes, then why we have to set it to a higher targetSdkVersion? isn't that set it lower can support more devices? What can be the differences?


Solution

  • If the user is using Android v24 or above, can they run my app as my targetSdkVersion is 21

    Yes.

    isn't that set it lower can support more devices?

    No. targetSdkVersion has no direct impact on what devices you can support. That is the role of minSdkVersion.

    targetSdkVersion controls some features added to newer versions of Android. The way I tend to describe targetSdkVersion in class is "it's the version of Android that you were thinking of when you wrote the code". Newer versions of Android, seeing your older targetSdkVersion, may elect to behave like the older version of Android, to make it more likely that your app will behave normally. For example, with your targetSdkVersion, you do not need to implement runtime permission support for dangerous permissions, the way you do with a targetSdkVersion of 23 or higher.

    then why we have to set it to a higher targetSdkVersion?

    Generally, you don't have to. Hopefully, nobody is pointing a gun at your head to force you to change this value.

    Certain library authors will tell you that you need to have a certain targetSdkVersion for their libraries to work reliably. The biggest example of this is the Android Support Library artifacts, where they want the major version of the artifact to match your compileSdkVersion and targetSdkVersion.

    Also, sometimes, the user will perceive your app as being old, because of an old targetSdkVersion. For example, your app will not support runtime permissions, and so at install time, the user has to agree to your permissions. The user might see that and think that your app is not being maintained, then elect to abandon the installation and find some other app that looks more maintained.