Jon
Jon

Reputation: 8021

Android: Is there an advantage to setting compileSdkVersion to a lower version than the latest api?

Is there any advantage to setting the compileSdkVersion in the manifest to less than the latest api build number, or should you always set it to the latest api build?

android {
    compileSdkVersion 22

When I say advantage I mean in terms of performance of the app, of compile time of the app, of size of the apk etc. I'm speaking, of course, of cases where you can set it lower - i.e. an app that doesn't use shared transitions or any features of lollipop.

Upvotes: 4

Views: 1444

Answers (3)

Stephan Branczyk
Stephan Branczyk

Reputation: 9375

No, there is not.

Also, thanks to commonsware for pointing that out, but there is a difference between compileSdkVersion and targetSdkVersion. See this previous answer on Stackoverflow.

Just don't set it to the latest M Preview right now. Not that you did, I'm just saying this for new Android developers that are reading this. Android M is a preview version and it's not meant for apps in production yet.

That being said, if you're just editing the code of an application that someone wrote a couple of years ago and your boss tells you not to waste more time than you have to on a tiny little change he wants you to make, then you might as well stick to that plan and only compile to the initial api that was originally used.

Also, there is the case of security audits and certifications. If a government agency or a security company hasn't had the time to audit the latest version of an OS or sdk, then you may be stuck compiling only to the version that was last certified.

Upvotes: 4

BladeCoder
BladeCoder

Reputation: 12929

First, there is a difference between targetSdkVersion and compileSdkVersion.

compileSdkVersion

The compileSdkVersion gives your app access to the newest APIs, styles and themes. You will have a compilation error if you try to use an API introduced in a more recent Android version than compileSdkVersion.

targetSdkVersion

targetSdkVersion indicates which API version your app has been tested against.

Targeting an older version enables compatibility behaviours, to make sure the app continues to work the same way.

Updating the targetSdkVersion to a newer version may introduce subtle behaviour changes, so make sure your know the new APIs and test the app properly if you do that. For example: calling AlarmManager.set() when targeting API < 19 will schedule the alarm at the exact time, because that's how it used to work before. Calling the same method while targeting API 19+ will allow the system to adjust the alarm delivery time by a few minutes to save battery life, and if you want the exact time behaviour you need to call the new method AlarmManager.setExact().

The compileSdkVersion must always be equal or higher than the targetSdkVersion.

Upvotes: 3

insa_c
insa_c

Reputation: 2931

No actually it does not make any changes. But i would suggest you to use the latest one to compile it just to be sure.

Upvotes: 2

Related Questions