简体   繁体   中英

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?

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

isCoreLibraryDesugaringEnabled = true

For versions before that, use:

coreLibraryDesugaringEnabled = true

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM