Does compilation SDK include values ​​returned by Android functions?

Suppose I have device A and my application is compiled twice: first I set compileSDK = 8, the second time I set compileSDK = 22. When I now call the function from the Android system, is it possible that the system will return two different values ​​or objects? I think this is impossible, since it depends on the system running on the device, and the compilation process with the SDK compiler only confirms that it works, but one of my colleagues claims that there can be different outputs. (Sorry for the lack of examples here.)

+3
source share
1 answer

The compiled version simply tells your compiler which Android classes and functions are available. for example, if you try to use the method introduced in v11, and your compilation version is 8, you will get a compilation error.

I believe that if there was a constant value that changed between 8 and 11, it could have compiled differently for your application, but this is unlikely because Android developers will know the problems that may cause, and this will violate their principle advanced compatibility :

Since almost all changes to the API are additive, an Android application developed using any particular version of the API (as defined by its API level) is compatible with later versions of the Android platform and higher API levels.

However, the tip here is :

In general, you should compile your application with the lowest possible version of the platform that your application can support.

i.e. compile version = min sdk version

(Note that one exception would be when you need the API functions from a later API, but you intend to Build.VERSION checking out Build.VERSION . In this case, you need a higher compilation version than the minimum).

To refer to your application:

I think this is not possible, since it depends on the operation of the system

It is important to note that devices with an API higher than targetSdkVersion will try to emulate the lower level of the target API :

As Android evolves with each new version, some changes in behavior and even appearance may change. However, if the API level on the platform is higher than the version claimed by your targetSdkVersion application, the system can enable compatibility behavior to ensure that your application continues to work as you expect.

+1
source

All Articles