Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is compileSdkVersion?

Just moved from Eclipse to Android studio yesterday and I'm trying to figure everything out. In my build grade, I now see a "compileSdkVersion" and I can't seem to figure out what it is. I know that minSdk tells GooglePlay how old of a device the app can handle. And that targetSdk tells the device weather or not it should switch to forward compatibility. But I don't know what compileSdk is and what I should do with it. Also, as a side question, if I set targetSdk as 21, devices running on sdk 16 run in compatibility mode? Thanks for your help! I really appreciate it!

EDIT: I kindly ask not to link me to the android developer website. I've read it and I don't understand why compiling in a different sdk makes a difference if there is already min, max and target sdk versions. Again, thanks alot for the help!

Here's the gradle code.

apply plugin: 'com.android.application'

android {
compileSdkVersion 17 
buildToolsVersion "19.1.0"

defaultConfig {
    applicationId "com.devname.myapp"
    minSdkVersion 10
    targetSdkVersion 21
}

buildTypes {
    release {
        runProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
    }
}
}

dependencies {
compile 'com.android.support:support-v4:21.0.0'     
compile files('libs/libGoogleAnalyticsServices.jar')
}
like image 825
tashad Avatar asked Dec 08 '22 05:12

tashad


2 Answers

The replies to my post were great, but I needed it dumbed down to me.

My long in-dept explanation is here.

TL;DR of my in-depth explanation

targetSdk means you've tested it on that device and your app is guaranteed to work on every device up to that. It is basically a "heads up" to android saying your app will work on everything up to that. If the device version is higher that this, android will automatically apply compatibility settings to the device in question. If the android version is lower than this, it will work normally because targetSdk means UP TO what version your app is set to work for. If I set targetSdk 16, then everything up to 16 will work, and all devices that use API versions above 16 will automatically go into compatibility mode to allow for it to work normally.

compileSdk = How many features does your app use. If it uses features that are only available on Android L, then you must compile your app with API 21 because that is the API version for Android L. If you use a lower compileSdk version, your app won't build because it won't be able to find the features that your app has since those features are not in those lower versions. If your app does not use features that are specifically on higher versions, then you can leave it alone. On average, if your app doesn't use anything exclusive to new Android versions, then just set compileSdk to 17.

Wait, but what's the difference between targetSdk and compileSdk?

Good question. targetSdk is basically a heads up to the Android operating system that says "Hey, this app is guaranteed to work for all devices up to this number because I tested it out."

compileSdk is basically talking to the Android Development Software "Hey, when you build this app, make sure you include all the features from this Android version because I need those features for the app to work.

This is only if you use the features from that Android release!

If you are not using features inside Lollipop, then there is no reason to set the compileSdk to 21! Why would you? You don't need it, so no reason to build it with all those extra features.

like image 117
tashad Avatar answered Dec 11 '22 10:12

tashad


compileSdkVersion is version of API which will be used to compile with for some compatibility purposes, as other answering fellas said

an example: pre-honecomb devices has "options" (settings?) button and all of them have physical keys. if you have a device without physical keys (on-screen only, honeycomb and up) when you compile with API 8 you will get menu indicator (three dots button) next to switch application button (right corner), but when compiling with 11 it will be gone - these three dots should be on your ActionBar (or whatever method you use for opening menu)

also: if you are looking for compileSdkVersion in Eclipse this number is in right click on project -> Properties -> Android (and on the list) or you might simply open project.properties file (pre-ics default.properties) and look for target (yes, in here named target)

like image 42
snachmsm Avatar answered Dec 11 '22 11:12

snachmsm