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

升级Compose 1.4.0与Kotlin 1.8.0后依赖解析失败求助

解决Compose Compiler 1.4.0 + Kotlin 1.8.0的依赖解析失败问题

嘿,我帮你捋捋这个问题!你遇到的核心问题是Compose Compiler版本和Compose UI库版本搞混了——这俩是分开维护的,版本号并不完全同步,你错误地把UI库的版本也设成了1.4.0,但实际上这个版本的UI库根本不存在。

为什么会这样?

Compose Compiler 1.4.0对应的稳定版Compose UI库版本是1.5.0,官方是通过Compose BOM(物料清单)来统一管理这些依赖版本的,确保Compiler和所有UI库版本兼容。

解决方案:用Compose BOM统一管理版本

最稳妥的方式是引入Compose BOM,它会自动帮你匹配所有兼容的Compose库版本,不用手动一个个指定。具体配置步骤如下:

1. 项目级build.gradle(或build.gradle.kts)添加BOM依赖

// Groovy版本
dependencies {
    implementation platform('androidx.compose:compose-bom:2023.03.00')
}
// Kotlin DSL版本
dependencies {
    implementation(platform("androidx.compose:compose-bom:2023.03.00"))
}

这个BOM版本(2023.03.00)正好对应Compose Compiler 1.4.0和Kotlin 1.8.0的组合。

2. 模块级build.gradle配置Compiler和UI库

只需要指定Compiler版本,UI库不需要加版本号,BOM会自动帮你匹配正确的1.5.0版本:

// Groovy版本
android {
    buildFeatures {
        compose true
    }

    composeOptions {
        kotlinCompilerExtensionVersion '1.4.0' // 这里指定Compiler版本
    }
}

dependencies {
    // 无需指定版本,由BOM管理
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-tooling'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    testImplementation 'androidx.compose.ui:ui-test-junit4'
    androidTestImplementation 'androidx.compose.ui:ui-test-manifest'
}
// Kotlin DSL版本
android {
    buildFeatures {
        compose = true
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.0"
    }
}

dependencies {
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-tooling")
    implementation("androidx.compose.ui:ui-tooling-preview")
    testImplementation("androidx.compose.ui:ui-test-junit4")
    androidTestImplementation("androidx.compose.ui:ui-test-manifest")
}

备选方案:手动指定UI库版本

如果你不想用BOM,也可以直接把所有UI库的版本改成1.5.0,同样能解决问题。比如:

implementation 'androidx.compose.ui:ui:1.5.0'
implementation 'androidx.compose.ui:ui-tooling:1.5.0'
// 其他依赖同理

这样配置后,依赖解析失败的问题应该就能解决啦!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 16:10:28