简体   繁体   English

isCoreLibraryDesugaringEnabled 在 gradle kotlin dsl / kts 中不起作用

[英]isCoreLibraryDesugaringEnabled not works in gradle kotlin dsl / kts

To enable desugaring in our android-library module we must put this in build.gradle :要在我们的 android-library 模块中启用脱糖,我们必须将其放在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:但是我们所有的脚本都迁移到了 gradle kotlin dsl,所以问题出现在build.gradle.kts三个方面:

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 .每次抛出Unresolved reference: isCoreLibraryDesugaringEnabled

Does anybody have an idea how to fix this?有人知道如何解决这个问题吗?

If you're using Android Gradle Plugin version >= 4.1, use:如果您使用的是 Android Gradle 插件版本 >= 4.1,请使用:

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.当我切换到较新的 android 插件版本 (4.1.0-rc02) 时,它理论上可以工作。 IDE says it's bad syntax, but it works during compilation. IDE 说这是错误的语法,但它在编译期间有效。

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解决方案类似于How to exclude (ignore) android build variant in gradle kts

It wasn't work because of missing line in top-level build.gradle.kts this line:由于缺少顶级build.gradle.kts这一行,它build.gradle.kts

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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