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

Android Studio解析Android应用模块Gradle配置失败问题排查

解决Gradle配置解析失败问题(Firebase + Jetpack Compose)

以下是针对你遇到的Could not parse the Android Application Module's Gradle config错误的具体修复方案:

1. 修复Kotlin与Compose编译器版本不兼容

Compose编译器版本和Kotlin版本存在严格的对应关系,当前项目中Kotlin版本为1.8.10,而Compose Compiler用的是1.4.3,两者不匹配(Kotlin 1.8.10对应Compose Compiler 1.4.6)。

修改app/build.gradle中的composeOptions块:

composeOptions {
    kotlinCompilerExtensionVersion '1.4.6'
}

2. 统一Compose依赖版本

当前compose_ui_version为1.4.0,但Material库版本是1.2.0,版本不统一会引发兼容性问题。调整app/build.gradle中的Material依赖:

implementation "androidx.compose.material:material:$compose_ui_version"

3. 统一Lifecycle组件版本

Lifecycle库版本不一致(lifecycle-runtime-ktx用2.3.1,其余Lifecycle Compose依赖用2.6.0),建议统一到兼容的稳定版本:

修改app/build.gradle中的Lifecycle相关依赖:

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2"
implementation "androidx.lifecycle:lifecycle-runtime-compose:2.6.2"

4. 清理顶层build.gradle的重复配置

顶层build.gradle中同时在buildscript和plugins块声明了google-services插件,属于重复配置,建议保留plugins块声明,调整后的顶层build.gradle如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
    id 'com.google.gms.google-services' version '4.3.15' apply false
}

ext {
    compose_ui_version = '1.4.0'
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

最后操作步骤

  1. 点击Android Studio右上角的Sync Project with Gradle Files按钮重新同步项目
  2. 若同步仍失败,执行File -> Invalidate Caches...,选择Invalidate and Restart重启Android Studio

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 23:43:09