Learning Android Development
Android Desugaring Made Easy
Understand How Android Support for Older Android SDK Made Possible
Published in
4 min readMay 30, 2023
Imagine if you need to use LocalDate.now()
for your App, and you need to support older than Android SDK 26 version, you will not have the code working by default.
If you put on your compiler, it will warn you as Call requires API level 26 (current min is 12): java.time.LocalDate#now
To resolve that, we’ll need to do something that is called Desugaring. In short, it is to add some additional configuration to your app module’s build.gradle
android {
defaultConfig {
// Required when setting minSdkVersion to 20 or lower
multiDexEnabled true
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}