To enable desugaring in our android-library module we must put this in build.gradle
:
android {
compileOptions {
coreLibraryDesugaringEnabled true
}
}
But we have all scripts migrated to gradle kotlin dsl, so the problem occurs in build.gradle.kts
in all three ways:
android {
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
}
configure<BaseExtension> {
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
}
android {
if (this is com.android.build.api.dsl.LibraryExtension<*, *, *, *, *, *, *, *, *, *, *>) {
buildFeatures.viewBinding = true
}
}
Every time it throws Unresolved reference: isCoreLibraryDesugaringEnabled
.
Does anybody have an idea how to fix this?
So put our lazy brain to work and create a file inside buildSrc naming it build.gradle.kts open now the newly created file to add some code that tells Gradle to enable the Kotlin-DSL plugin for our project. Sync now, That’s it Battle is won, and Kotlin DSL is enabled in our project.
These are the Kotlin compiler arguments used for compiling Kotlin DSL scripts and Kotlin sources and scripts in a project that has the kotlin-dsl plugin applied: Sets the target version of the generated JVM bytecode to 1.8.
The Kotlin DSL is fully supported by IntelliJ IDEA and Android Studio. Other IDEs do not yet provide helpful tools for editing Kotlin DSL files, but you can still import Kotlin-DSL-based builds and work with them as usual. Table 1.
Managing dependencies in large android projects is still cumbersome and hectic and that unfamiliar groovy syntax makes it even harder to understand the changes. Kotlin DSL brings the simplicity of the Kotlin language syntax and rich API set right into the script files on top of that code completion makes it perfect to work with Gradle script files.
If you're using Android Gradle Plugin version >= 4.1, use:
isCoreLibraryDesugaringEnabled = true
For versions before that, use:
coreLibraryDesugaringEnabled = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With