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

多模块应用中Jetpack Compose编译失败:无法连接Kotlin编译守护进程

解决多模块Android应用中Jetpack Compose的Kotlin编译守护进程连接问题

问题描述

无法执行增量编译:无法连接到Kotlin编译守护进程
无法连接到Kotlin守护进程,正在使用回退策略。
异常:java.io.EOFException

相关依赖及配置代码如下:

implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.2.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"

ext {
    kotlin_version = '1.6.21'
    compose_ui_version = '1.2.0'
}

buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerExtensionVersion '1.2.0'
}

可行解决方法

  • 清理构建环境并重启

    1. 执行命令./gradlew clean清除项目构建缓存
    2. 关闭Android Studio,手动终止所有Kotlin编译守护进程(Windows用任务管理器结束kotlin-daemon进程;Mac/Linux执行pkill kotlin-daemon)
    3. 重新打开Android Studio,重新执行构建
  • 统一多模块版本配置
    检查所有模块的kotlin_version和kotlinCompilerExtensionVersion,确保完全一致,避免多模块版本冲突导致守护进程异常。当前配置中Kotlin 1.6.21与Compose编译器1.2.0是兼容的,重点排查其他模块的版本是否统一。

  • 调整JVM内存分配
    在项目根目录的gradle.properties中增加内存配置,避免守护进程因内存不足崩溃:

    org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    kotlin.daemon.jvmargs=-Xmx4096m
    
  • 临时禁用增量编译
    如果以上方法无效,可在模块的build.gradle中临时关闭增量编译,排查是否为增量编译逻辑导致的问题:

    kotlin.incremental=false
    
  • 检查多模块Compose配置
    确保所有启用Compose的模块都正确配置了buildFeatures.compose=true,且依赖的Compose库版本统一,避免跨模块依赖冲突引发守护进程连接异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 15:55:17