16

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?

Krystian Kaniowski
  • 1,959
  • 17
  • 33

2 Answers2

39

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

isCoreLibraryDesugaringEnabled = true

For versions before that, use:

coreLibraryDesugaringEnabled = true
Saurabh Thorat
  • 18,131
  • 5
  • 53
  • 70
  • for version 4.0 if you use `coreLibraryDesugaringEnabled = true ` then compiler will say `Unresolved reference: coreLibraryDesugaringEnabled` – Krystian Kaniowski Sep 14 '20 at 07:07
2

When I switch to the newer android plugin version (4.1.0-rc02) it theoretically works. IDE says it's bad syntax, but it works during compilation.

if (this is com.android.build.api.dsl.LibraryExtension<*, *, *, *, *>) {
    compileOptions.isCoreLibraryDesugaringEnabled = true
}

However, it's not an ideal solution

----- FINAL SOLUTION -----

Solution is similar to How to exclude (ignore) android build variants in gradle kts

It wasn't work because of missing line in top-level build.gradle.kts this line:

classpath("com.android.tools.build:gradle:4.0.1")

Krystian Kaniowski
  • 1,959
  • 17
  • 33
  • Right. for me setting build tools to `4.0.1` and gradle version to `gradle-6.1.1-all.zip` worked. thanks. – omer Nov 18 '21 at 11:27
  • also I used `coreLib...` instead of `isCoreLib...` due to `4.0.1` and also I had to change kotlin version (due to some other jetifier errors in my case) as well to newer and compatible version. so had to change bunch of things.I am setting up a few months old project so facing these errors. – omer Nov 18 '21 at 11:46