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 t
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.