You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 assembleDebug
    

    Windows环境替换为gradlew.bat clean assembleDebug

内容的提问来源于stack exchange,提问作者Vic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 04:45:58