What are the differences between "min sdk version/target sdk version" and "compile sdk version"?

I know what min and target sdk means but what does compile sdk version mean? In eclipse I have min/max and target sdk but in android studio there are these three settings.

up vote 172 down vote accepted

To elaborate on @anuraagy's answer:

min sdk version Is the earliest release of the Android SDK that your application can run on. Usually this is because of a problem with the earlier APIs, lacking functionality, or some other behavioral issue.

target sdk version The version your application was targeted to run on. Ideally this is because of some sort of optimal run conditions. If you were to "make your app for version 19" this is where that would be specified. It may run on earlier or later releases, but this is what you were aiming for. This is mostly to indicate how current your application is for use in the marketplace, etc.

compile sdk version The version of android your IDE (or other means of compiling I suppose) uses to make your app when you publish a .apk file. This is useful for testing your application as it is a common need to compile your app as you develop it. As this will be the version to compile to an APK, it will naturally be the version of your release. Likewise it is advisable to have this match you target sdk version.

I didn't mean to rip off somebody else's answer, but I really hope this sheds some light on distinguishing these three terms.

  • My compile sdk version and target sdk version are the same. That is 21. My App crashes when I run it on devices with lower API level. I'm new to Android, how should I proceed now? – prgmrDev Jul 23 '15 at 11:15
  • 2
    @prgmrDev If your app crashes on versions lower than 21, you should probably set your min SDK version to 21. This will not actually fix your application on targets lower than 21, it will just note that your app is unsupported on lower versions. You also have the option of determining what exactly is breaking your application (what changed in version 21,) and add support to take care of that dependency, but I suspect that will be a lot of work and not within the scope of an Android beginner project. – Matt Jul 28 '15 at 20:25
  • 1
    What happens if I set my minSdkVersion =14; targetSdkVersion=23; and compile SDK to 19? – thadeuszlay Apr 20 '16 at 11:51
  • @thadeuszlay your question is irrelevant because you should think a little bit that if you target to run on version 23 then how is it possible to compile it with 19! Please follow the formula minSdkVersion <= targetSdkVersion <= compileSdkVersion – Asad Jul 28 at 8:00

Good Question!

min sdk version is the minimum version of the Android Operating System required to run your application.

target sdk version is the version of Android that your app was created to run on.

compile sdk version is the the version of Android that the build tools uses to compile & build the application in order to release, run, or debug.

Usually the compile sdk version and the target sdk version are the same.

  • 11
    And when they are not the same pros/cons? – powder366 Sep 11 '15 at 15:25

The formula is

minSdkVersion <= targetSdkVersion <= compileSdkVersion

minSdkVersion - is a marker that defines a minimum Android version on which application will be able to install. Also it is used by Lint to prevent calling API that doesn’t exist. Also it has impact on Build Time. So you can use build flavors to override minSdkVersion to maximum during the development. It will help to make build faster using all improvements that the Android team provides for us. For example some features Java 8 are available only from specific version of minSdkVersion.

targetSdkVersion - says Android system to turn on specific behavior changes.

Good example is dangerous permissions (from 23 API). If you set targetSdkVersion to 22 your application does not ask a user for some permission in run time.

Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel or it will not appear. On devices running Android 7.1 (API level 25) and lower, users can manage notifications on a per-app basis only (effectively each app only has one channel on Android 7.1 and lower).

compileSdkVersion - actually it is SDK Platform version and tells Gradle which Android SDK use to compile. When you want to use new features or debug .java files from Android SDK you should take care of compileSdkVersion. One more fact is compileSdkVersion >= Support Library version

You can read more about it here. Also I would recommend you to take a look at the example of migration to Android 8.0

See here, that's better to specify in target sdk version latest released version of the API: What is the difference between compileSdkVersion and targetSdkVersion?

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.