Android Gradle: Buildtoolsversion VS Compilesdkversion

Android gradle: buildtoolsVersion vs compileSdkVersion

compileSdkVersion is the API version of Android that you compile against.

buildToolsVersion is the version of the compilers (aapt, dx, renderscript compiler, etc...) that you want to use. For each API level (starting with 18), there is a matching .0.0 version.

At IO 2014, we release API 20 and build-tools 20.0.0 to go with it.

Between Android releases we will release updates of the compilers, and so we'll release version .0.1, .0.2, etc... Because we don't want to silently update these version under you, it's up to you to move to the new version when it's convenient for you.

You can use a higher version of the build-tools than your compileSdkVersion, in order to pick up new/better compiler while not changing what you build your app against.

What is difference between compileSdk and compileSdkVersion in android studio gradle script when using jetpack compose

With the new Android Gradle Plugin 7.0.0 (currently 7.0.0-alpha14) you can use:

  • minSdk instead of minSdkVersion
  • targetSdk instead of targetSdkVersion
  • compileSdk instead of compileSdkVersion

These attributes work with an Int and you can use them with something like:

//minSdkVersion 21
//targetSdkVersion 30
minSdk 21
targetSdk 30

If you want to use a preview version you have to use:

  • minSdkPreview
  • targetSdkPreview
  • compileSdkPreview

These attributes work with a String and setting these values will override previous values of minSdk/targetSdk/compileSdk.

About the String format of the preview versions currently (7.0.0-alpha14) it is not clear. Maybe it will change with 7.0.0-beta01 (you can check this commit) and it should be:

compileSdkPreview = "S"

buildToolsVersion and compileSdkVersion had been deprecated

It builds alike this (the library module needs to be changed):

plugins {
id "com.android.application"
}
android {
defaultConfig {
compileSdkVersion 31
}
}

plugins {
id "com.android.library"
}
android {
defaultConfig {
// compileSdkVersion 31
compileSdk 31
}
}

What is the buildToolsVersion for android SDK 24?

buildToolsVersion should be set to 25 and 25.0.0, as seen below:

compileSdkVersion 25
buildToolsVersion '25.0.0'
useLibrary 'org.apache.http.legacy'

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}

You can get the latest buildToolsVersion from SDK Manager in Android Studio.

What is the difference between compileSdkVersion and targetSdkVersion?

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 as long as your app's execution paths do not attempt to invoke any APIs specific to API 16.

targetSdkVersion

The targetSdkVersion has nothing to do with how your app is compiled or what APIs you can utilize. The targetSdkVersion is supposed to indicate that you have tested your app on (presumably up to and including) the version you specify. This is more like a certification or sign off you are giving the Android OS as a hint to how it should handle your app in terms of OS features.

For example, as the documentation states:

For example, setting this value to "11" or higher allows the system to apply a new default theme (Holo) to your app when running on Android 3.0 or higher...

The Android OS, at runtime, may change how your app is stylized or otherwise executed in the context of the OS based on this value. There are a few other known examples that are influenced by this value and that list is likely to only increase over time.

For all practical purposes, most apps are going to want to set targetSdkVersion to the latest released version of the API. This will ensure your app looks as good as possible on the most recent Android devices. If you do not specify the targetSdkVersion, it defaults to the minSdkVersion.



Related Topics



Leave a reply



Submit