Does the compile SDK affect values returned by Android functions?

后端 未结 1 1594
既然无缘
既然无缘 2021-01-20 16:29

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

1条回答
  •  被撕碎了的回忆
    2021-01-20 17:22

    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.

    0 讨论(0)
提交回复
热议问题