Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isCoreLibraryDesugaringEnabled not works in gradle kotlin dsl / kts

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?

like image 701
Krystian Kaniowski Avatar asked Sep 08 '20 08:09

Krystian Kaniowski


People also ask

How to enable Kotlin-DSL in Gradle?

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.

What are the Kotlin-DSL compiler arguments?

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.

Does IntelliJ support Kotlin-DSL?

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.

Why Kotlin for Android scripts?

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.


1 Answers

If you're using Android Gradle Plugin version >= 4.1, use:

isCoreLibraryDesugaringEnabled = true

For versions before that, use:

coreLibraryDesugaringEnabled = true
like image 127
Saurabh Thorat Avatar answered Sep 26 '22 12:09

Saurabh Thorat