Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between min SDK version/target SDK version vs. compile SDK version?

People also ask

What is the difference between compile SDK version and target SDK version?

compileSdkVersion is the version of the compiler used in building the app, while targetSdkVersion is the "API level that the application targets".

What is the difference between minimum target and compiled SDK?

minSdkVersion should be lower to target the max coverage of android devices on which the app will be installed. compileSdkVersion is required while developing the app to use the latest and optimize APIs of android.

Should compile and target SDK be the same?

Ideally, the compileSdkVersion and targetSdkVersion should be equal and both point to the latest SDK. But of course only after you test that every change introduced in that version works smoothly with your app!

What is Min SDK version?

android:minSdkVersion — Specifies the minimum API Level on which the application is able to run. The default value is "1". android:targetSdkVersion — Specifies the API Level on which the application is designed to run.


The 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 behavioural issue.

The target sdk version is 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.

The compile sdk version is 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 your target sdk version.


minSdkVersion, targetSdkVersion, compileSdkVersion

The formula is

minSdkVersion <= targetSdkVersion <= compileSdkVersion

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

targetSdkVersion - If AndroidOS version is >= targetSdkVersion it says Android system to turn on specific(new) behavior changes. *Please note that some of these new behaviors will be turned on by default even if thought targetSdkVersion is <, you should read the official documentation.

For example:

  • Starting in Android 6.0 (API level 23) Runtime Permissions were introduced. If you set targetSdkVersion to 22 or lower 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).

  • Starting in Android 9 (API level 28), Web-based data directories separated by process. If targetSdkVersion is 28+ and you create several WebView in different processes you will get java.lang.RuntimeException

compileSdkVersion - actually it is the SDK Platform version and tells Gradle which Android SDK uses to compile. When you want to use new features or debug .java files from Android SDK you should take care of compileSdkVersion. One more example is using AndroidX that forces to use compileSdkVersion - level 28. compileSdkVersion is not included in your APK: it is purely used at compile time. Changing your compileSdkVersion does not change runtime behavior. It can generate for example new compiler warnings/errors. Therefore it is strongly recommended that you always compile with the latest SDK. You’ll get all the benefits of new compilation checks on existing code, avoid newly deprecated APIs, and be ready to use new APIs. 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.

[buildToolsVersion]


The min sdk version is the minimum version of the Android operating system required to run your application.

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

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

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


compileSdkVersion : The compileSdkVersion is the version of the API the app is compiled against. This means you can use Android API features included in that version of the API (as well as all previous versions, obviously). If you try and use API 16 features but set compileSdkVersion to 15, you will get a compilation error. If you set compileSdkVersion to 16 you can still run the app on a API 15 device.

minSdkVersion : The min sdk version is the minimum version of the Android operating system required to run your application.

targetSdkVersion : The target sdk version is the version your app is targeted to run on.


Reference- Medium Article by Paulina Sadowska

  1. compileSdkVersion defines which Android SDK version will be used by Gradle to compile your app.

For example:

In Android 12, so in SDK version 31, there was a new API introduced, that allows us to easily implement a splash screen. In this new API, the splash screen can be customized using those properties:

If you want to use that API in your app you first have to:

i)  download SDK version 31 in Android Studio,
ii) and then: update compileSdkVersion to 31 in your app.

Only then you can see these new properties. And only then you can use this new splash screen API in your code.

2.targetSdkVersion is a property that tells the system for which Android version the app was designed and tested on.

If the user runs your app on a device with an android version that is higher than the targetSdkVersion defined in your app, for new android features, the system may introduce some backward-compatibility behavior to ensure your app still looks and works in a way that you designed it.

For example:

In Android 12 the appearance of custom notifications was changed. Previously they could use the whole notification area, but in Android 12 system applies the standard template to all custom notifications so they look more consistent. If your targetSdkVersion is below 31 system will assume that you haven’t tested that feature and will display notifications in the old way to minimize the risk that notification will not be displayed properly. Only after you update the target SDK version to 31 the new notification appearance will be used.