Everytime I get confused with this and I do search and I “think” I understood it but I appear not too.
Can someone explain to me whats the difference between the API you are building against and Min SDK you specify in your manifest and the target SDK you specify.
For example:
I have an application that its minSDK is 8 and targetSDK is 15 and I build against SDK 12. What’s the difference? What devices does it run on? What do I gain from these differences!
Someone please explain!
Thank you
The difference is the result of subtracting two numbers. But that’s not important here. 🙂
That depends on your code as much as anything else. However, it will not run on API Level 7 and below, as those fall below your
minSdkVersion. Android devices (and markets) will not allow your app on API Level 7 and lower devices.By setting a build target of 12, you are saying to the compiler and build tools: “I want to use APIs newer than those from API Level 8, up through API Level 12, but I promise to do so in such a way as to avoid those newer APIs on the older devices”. The build tools, Lint in particular, will yell at you when you try using newer APIs without appropriate protection (e.g., checking
android.os.Build.SDK_INT).By setting
android:targetSdkVersionto 15, you are saying to the compiler and build tools: “When I wrote this code, I was thinking about API Level 15”. Devices newer than your target may elect to do things differently, to try to better emulate life back on API Level 15.The best example of the latter is
AsyncTask. Traditionally, tasks could run in parallel. However, if you haveandroid:targetSdkVersionset to 13 or higher, and you are running on an API Level 13 or higher device, then tasks will execute serially by default. If you run on an a device that is API Level 13 or higher, but yourandroid:targetSdkVersionis 12 or lower, the device will fall back to the old behavior, to maintain compatibility.