Lets assume I am having a device A and my app is compiled two times: first time I set compileSDK=8, second time i set compileSDK=22. When I am now calling a function from the Android system would it be possible that the system returns two different values or objects? I think this is not possible as this depends on the system running on the device and the compile process against a compile SDK only does assert that it works - but one of my collegues states that this might be possible to have different outputs here. (Sorry for not having any examples here..)
1 Answers
Compile version simply tells your compiler which android classes and functions are available. e.g. If you attempt to use a method introduced in v11 and your compile version is 8, then you'll get a compilation error.
I suppose if there was a constant value that changed between 8 and 11, it could get compiled in differently to your app, but this is unlikely because the android developers would know the problems that would cause and it would break their principle of forward compatibility:
Because almost all changes to the framework API are additive, an Android application developed using any given version of the API (as specified by its API Level) is forward-compatible with later versions of the Android platform and higher API levels.
Even so, the advice from here is:
In general, you should compile your application against the lowest possible version of the platform that your application can support.
i.e. compile version = min sdk version
(Note, one exception would to this would be when you need API features from later API, but you intend to safely fall back by checking Build.VERSION
. In that case you need a higher compile version than the minimum).
To address your statement:
I think this is not possible as this depends on the system running
It's important to note that devices with an API higher than the targetSdkVersion
will attempt emulate down to the lower target API level:
As Android evolves with each new version, some behaviors and even appearances might change. However, if the API level of the platform is higher than the version declared by your app's
targetSdkVersion
, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect.

- 54,145
- 21
- 145
- 203
-
Thanks for your answer, the current problem is that when using AppCompat it's unfortunately not possible to use the minSDK as the compileSDK because the lib references assets that are not available in these SDKs so do you think there is any appropriate workaround (besides copying the whole sdk assets..), so my question is are there (known) negative impacts from changing the compileSDK from min to i would say max? – and_dev Aug 30 '15 at 10:04
-
Not that I know of, in fact till I researched this answer I've been doing it wrong and putting compile==target all the time. Never hurt my apps. With that principle of forward compatibility, it shouldn't. What do you mean max though? because you shouldn't use `maxSdkVersion` – weston Aug 30 '15 at 10:08
-
Well I also did it like you (compile==target), with max I meant the "maximum" sdk version needed for Appcompat to resolve assets. – and_dev Aug 30 '15 at 10:11
-
I always target the highest API device I have, and I test on that mainly. Then I recommend testing against the oldest API you support to completely satisfy any concerns. Either with real device or emulator image. – weston Aug 30 '15 at 10:14
-
I asked a related question which I hope may help you too http://stackoverflow.com/questions/32295866/should-compile-sdk-be-lower-than-target-sdk – weston Aug 30 '15 at 16:09
-
Well thanks, I think the question answered by @CommonsWare was quite helpful. – and_dev Aug 31 '15 at 05:22