Android构建报错:创建'Record desugaring'全局合成类时无全局合成消费者
解决D8构建错误(Record desugaring相关)
错误信息
ERROR:D8: Invalid build configuration. Attempt to create a global synthetic for 'Record desugaring' without a global-synthetics consumer.
环境信息
- Java版本:17
- Android API版本:32
解决方案
启用核心库脱糖并配置依赖:
在模块级build.gradle(Groovy)中添加:android { compileOptions { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } } dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4' }若使用KTS(
build.gradle.kts):android { compileOptions { isCoreLibraryDesugaringEnabled = true sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } } dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4") }升级Gradle插件版本:
在项目级build.gradle(Groovy)中更新插件版本:dependencies { classpath 'com.android.tools.build:gradle:7.4.2' }KTS版本:
dependencies { classpath("com.android.tools.build:gradle:7.4.2") }清理并重新构建:
执行命令:./gradlew clean assembleDebugWindows环境替换为
gradlew.bat clean assembleDebug
内容的提问来源于stack exchange,提问作者Vic
相关产品推荐
相关产品推荐

