45

I've just noticed in a library module, that compileSdkVersion and buildToolsVersion had recently been deprecated. These are the two configurations, which it complains about (strikethrough text). This currently only affects com.android.library, not com.android.application:

plugins {
    id "com.android.library"
}
android {
    defaultConfig {
        compileSdkVersion 31
        buildToolsVersion "31.0.0"
    }
}

Screenshot: build.gradle

When clicking through, on may notice that com.android.build.gradle.AndroidConfig had been deprecated in favor of BaseExtension (whatever that may mean for a matching build.gradle):

Screenshot: Fernflower


Apparently compileSdkVersion is now called compileSdk (this part seems to work) ...and buildToolsVersion has to be defined as a property. But when building (it's not that I've not tried), property buildToolsVerson = "31.0.0" is unknown:

android {
    defaultConfig {
        compileSdk 31
        buildToolsVersion = "31.0.0"
    }
}

How to make it build without deprecation warnings?

Martin Zeitler
  • 1
  • 19
  • 155
  • 216

5 Answers5

23

If you see this error 'compileSdkVersion' is deprecated For new SDK 33:

apply plugin: 'com.android.application'

android {
   // compileSdkVersion 33
    defaultConfig {
        compileSdk 33
    }
...}
Mori
  • 2,653
  • 18
  • 24
  • 3
    This one removed my warning. BUT, I do not get the logic behind: For "minSdkVersion" and "targetSdkVersion", the "Version" postfix is OK (and pretty meaningful to me). BUT in "compileSdkVersion", the "Version" postfix is a problem. Are Google product owners on drugs ? – Jiří Křivánek Aug 16 '23 at 05:59
  • I've changed "compileSDKversion" to "compile SDK", but buildToolsVersion = '30.0.3' is still deprecated. Should I delete the string " buildToolsVersion = '30.0.3' " completely? – bic55 Aug 21 '23 at 10:26
  • 2
    Hi @bic55, You can safely remove `buildToolsVersion = '30.0.3'` because according to the documentation: _If you're using Android plugin for Gradle 3.0.0 or higher, your project automatically uses a default version of the build tools that the plugin specifies._ – Amc Aug 24 '23 at 08:28
16

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
    }
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • 2
    It is no longer necessary to specify **buildToolsVersion** if you're using Android plugin for Gradle 3.0.0 or higher, because your project automatically uses a default version of the build tools that the plugin specifies. – Amc Aug 24 '23 at 08:33
10
compileSdk 33
buildToolsVersion = '30.0.3'
Nicolas
  • 6,611
  • 3
  • 29
  • 73
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 13 '23 at 03:15
  • 1
    I've changed "compileSDKversion" to "compile SDK", but buildToolsVersion = '30.0.3' is still deprecated – bic55 Aug 21 '23 at 10:23
7

If you are using a kts gradle file instead (build.gradle.kts)

plugins {
    id("com.android.library")
}
android {
    defaultConfig {
        // compileSdkVersion 31
        compileSdk = 31
    }
}
Chris
  • 4,662
  • 2
  • 19
  • 27
1
apply plugin: 'com.android.application'

android {
    defaultConfig {
        buildToolsVersion = '30.0.3'
        compileSdk = 31
    }
}
WilliaGuy
  • 111
  • 2
  • 7