Advertisement
Guest User

compileSdk vs. targetSdk - StackOverflow

a guest
Dec 4th, 2014
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. Okay I just figured it all out and I'll explain here.
  2.  
  3. The replies to my post were great, but when I don't understand something, I need it explained very easily and slowly. I'll explain it for those who find this in the future. So here is what I got:
  4.  
  5. minSdkVersion means how old of a phone your app will handle until it can't work. If you set this to 19 (Android KitKat 4.4) then devices on 16 (Android ICS 4.0) can't run it since it is older than KitKat.
  6.  
  7. With the above in mind, maxSdkVersion is pretty self explanatory.
  8.  
  9. Both minSdk and maxSdk WILL impact your app on Google Play. Devices that are not compatible with your app will not be able to see it.
  10.  
  11. targetSdkVersion is the device you have tested your app to. If I tested my app on a Nexus 6 running Lollipop, and everything worked as expected, then I will set targetSdk to 21 because my app worked perfectly on API 21 (Lollipop 5.0).
  12.  
  13. compileSdk means the API number you want your app to COMPILE with. So let me explain this. For starters, know that different versions of android have different features. That's what makes an update. A good example is that old versions of android like ones with API 11 don't have those nice new Holo app themes but new ones like ones with API 16,17,18,19,20,21 (Ice Cream Sandwich, KitKat, Lollipop) do have those. So if you compile with API 11, and your app uses those new features from the newer API's like a holo theme, then your app won't work because you are trying to use features that are exclusive to newer versions. But if you compile with API 21, your app will work because it has all the new features.
  14.  
  15. Wait, but what's the difference between targetSdk and compileSdk?
  16.  
  17. Good question. targetSdk is basically a heads up to the Android operating system that says "Hey, this app is guaranteed to work for all devices up to this number because I tested it out."
  18.  
  19. compileSdk is basically talking to the Android Development Software "Hey, when you build this app, make sure you include all the features from this Android version because I need those features for the app to work.
  20.  
  21. This is only if you use the features from that Android release!
  22.  
  23. If you are not using features inside Lollipop, then there is no reason to set the compileSdk to 21! Why would you? You don't need it, so no reason to build it with all those extra features.
  24.  
  25. BUT, say you are using a nice Holo theme on your app and you set your compileSdk to 11. Then it won't build. The Android software will start building then, it will be like, "wait, what's a holo theme?" because the version you compiled with doesn't have that feature! But if you compiled with API20 for example, the Android software will build and think "He want's a holo theme, oh there it is." and the building will complete successfully. But if I compile with 20 and use features from 21, it won't work.
  26.  
  27. compileSdk is basically telling Android how many features to include in the app file.
  28.  
  29. If you have an app that does not use and features that are SPECIFIC to Android Lollipop (API 21), then you don't set compileSdk to 21 because your app doesn't use any of those extra features.
  30.  
  31. If you know your app will run just fine on Android L though (API 21) then go ahead and change your tardgetSdk to 21 because it will still work on Android L devices.
  32.  
  33. TL;DR
  34.  
  35. minSdk/maxSdk = Up to what version your app will work on. If device version is less that minSdk, app will not work and will not show up on Google Play. If device version is higher than maxSdk, same outcome. Usually no reason to set maxSdk!!!
  36.  
  37. targetSdk means you've tested it on that device and your app is guaranteed to work on every device up to that. It is basically a "heads up" to android saying your app will work on everything up to that. If the device version is higher than this, android will automatically apply compatibility settings to the device in question. If the android version is lower than this, it will work normally because targetSdk means UP TO what version your app is set to work for. If I set targetSdk 16, then everything from minSdk to 16 will work, and all devices that use API versions above 16 will automatically go into compatibility mode to allow for it to work normally.
  38.  
  39. compileSdk = How many features does your app use. If it uses features that are only available on Android L, then you must compile your app with API 21 because that is the API version for Android L. If you use a lower compileSdk version, your app won't build because it won't be able to find the features that your app has since those features are not in those lower versions. If your app does not use features that are specifically on higher versions, then you can leave it alone. On average, if your app doesn't use anything exclusive to new Android versions, then just set compileSdk to 17.
  40.  
  41. Happy Coding!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement