buildToolsVersion and compileSdkVersion had been deprecated

Viewed 917

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?

2 Answers

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
    }
}

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

plugins {
    id("com.android.library")
}
android {
    defaultConfig {
        // compileSdkVersion 31
        compileSdk = 31
    }
}
Related