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

升级Firebase依赖与Kotlin版本后app:kaptDebugKotlin任务执行失败求助

升级Firebase BOM与Kotlin版本后项目构建失败问题排查

问题背景

  • 执行操作:升级firebase-bom:32.2.2以更新Firebase Crashlytics、Analytics依赖;将Kotlin版本从1.5.21升级至1.8.0
  • 出现问题:项目无法正常构建

常见排查与修复步骤

1. 匹配Gradle插件与Kotlin版本兼容性

Kotlin 1.8.0需搭配对应版本的Gradle及Android Gradle Plugin(AGP),建议使用Gradle 7.4+、AGP 7.4.0+。在项目级构建文件中确认配置:

// 项目级build.gradle
buildscript {
    dependencies {
        classpath "com.android.tools.build:gradle:7.4.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
        classpath "com.google.gms:google-services:4.4.0"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.9.9"
    }
}

2. 统一通过Firebase BOM管理依赖

确保所有Firebase依赖不单独指定版本,由BOM统一管控,应用级构建文件中配置:

// 应用级build.gradle
dependencies {
    implementation platform('com.google.firebase:firebase-bom:32.2.2')
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-analytics'
}

3. 清理构建缓存并重新同步

  • 执行Gradle命令:./gradlew clean build --refresh-dependencies
  • 在Android Studio中选择File > Invalidate Caches... > Invalidate and Restart

4. 检查Kotlin生态依赖兼容性

确保项目中Kotlin相关依赖(如Coroutines、Serialization等)版本适配Kotlin 1.8.0,例如:

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"

5. 定位具体错误

若上述步骤无效,需结合错误堆栈跟踪分析:

  • 提取构建日志中的核心错误信息(如依赖冲突、语法报错、AGP兼容问题)
  • 使用./gradlew app:dependencies查看依赖树,排查并排除冲突依赖

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 07:00:17