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

更新Java、Gradle和Flutter后无法解析com.android.tools.build:gradle:8.9.0依赖

Flutter项目构建错误排查与解决

错误日志

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project 'android'.

Could not resolve all artifacts for configuration ':classpath'.
Could not find com.android.tools.build:gradle:8.9.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/8.9.0/gradle-8.9.0.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/8.9.0/gradle-8.9.0.pom
Required by:
project :
Could not find org.codehaus.groovy:groovy-all:latest_version.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-all/latest_version/groovy-all-latest_version.pom
- https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-all/latest_version/groovy-all-latest_version.pom
Required by:
project :

项目配置详情

android/build.gradle

buildscript {
    ext.kotlin_version = '1.8.22'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.9.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle

plugins {
    id "com.android.application"
    id 'com.google.gms.google-services'
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace 'com.example.chat'
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId = "com.example.chat"
        minSdkVersion 23 
        targetSdkVersion 33
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }
    buildTypes {
        release {
            signingConfig = signingConfigs.debug
        }
    }
    configurations.all {
        resolutionStrategy {
            force 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22'
        }
    }
}

wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

环境信息

  • Java version: 22.0.2 (build 22.0.2+9-70)
  • Gradle version: 8.9
  • Flutter version: 最新版

问题原因与解决步骤

核心原因

  1. AGP版本未发布:com.android.tools.build:gradle:8.9.0并非官方已发布的稳定版本,AGP版本号与Gradle版本并非完全同步,存在版本兼容匹配要求。
  2. 无效版本占位符:Maven仓库不支持latest_version作为依赖版本号,必须指定具体有效版本。

解决步骤

  1. 修正AGP版本
    将android/build.gradle中的AGP版本替换为当前官方已发布的稳定版(例如8.7.2):

    classpath 'com.android.tools.build:gradle:8.7.2'
    

    注:Gradle 8.9与AGP 8.7.x版本兼容,无需修改gradle-wrapper.properties中的Gradle版本。

  2. 修复Groovy依赖版本
    若groovy-all为间接依赖,可在buildscript的dependencies中添加具体版本的依赖声明:

    classpath 'org.codehaus.groovy:groovy-all:3.0.19'
    

    该版本与Gradle 8.9兼容。

  3. 清理缓存并同步项目

    • 执行flutter clean清理Flutter项目缓存
    • 执行./gradlew clean build --refresh-dependencies强制刷新Gradle依赖
    • 重新运行Flutter项目

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 18:50:20