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

Flutter Gradle插件DSL迁移报错:找不到com.android.tools.build:gradle:7.3.3

Flutter迁移Plugin DSL语法后构建报错:找不到com.android.tools.build:gradle:7.3.3

问题描述

尝试将Flutter项目迁移至新的Plugin DSL语法,构建时持续报错,提示找不到com.android.tools.build:gradle:7.3.3,但项目配置中并未显式引用该版本。

报错信息

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gradle:compileGroovy'.
> Could not resolve all files for configuration ':gradle:compileClasspath'.
   > Could not find com.android.tools.build:gradle:7.3.3.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
       - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
     Required by:
         project :gradle

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 775ms
Error: Gradle task assembleDebug failed with exit code 1

项目配置文件

settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.1.1" apply false
    id "org.jetbrains.kotlin.android" version "2.0.0" apply false
    id "com.google.gms.google-services" version "4.3.10" apply false
    id "com.google.firebase.crashlytics" version "2.8.1" apply false
}

include ":app"

build.gradle

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
}

app/build.gradle

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

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }
android {
   

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID
        applicationId "de.groschopp.gromotorcontroller"
        minSdkVersion 21
        compileSdkVersion 35
        targetSdkVersion 35
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

gradle-wrapper.properties

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.5-all.zip

环境信息

dusan@Dusans-MacBook-Pro gromoc_mobile % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.3, on macOS 14.5 23F79 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
      Download at: https://developer.apple.com/xcode/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.87.2)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.
dusan@Dusans-MacBook-Pro gromoc_mobile % java -version
java version "19" 2022-09-20
Java(TM) SE Runtime Environment (build 19+36-2238)
Java HotSpot(TM) 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)

解决方案

问题根源

Flutter 3.22.3自带的Gradle插件依赖com.android.tools.build:gradle:7.3.3,但当前配置的Android Gradle插件版本(8.1.1)与Flutter版本不兼容,导致依赖链冲突;同时Plugin DSL模式下,插件依赖的解析由pluginManagement块的仓库配置主导,版本不匹配会引发无法找到依赖的问题。

修复步骤

  1. 调整Android Gradle插件与Kotlin版本
    修改settings.gradle中的插件版本,适配Flutter 3.22.3:

    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        id "com.android.application" version "7.4.2" apply false // 与Flutter 3.22.3兼容
        id "org.jetbrains.kotlin.android" version "1.8.22" apply false // 匹配Android插件版本
        id "com.google.gms.google-services" version "4.3.10" apply false
        id "com.google.firebase.crashlytics" version "2.8.1" apply false
    }
    
  2. 同步Gradle wrapper版本
    修改gradle-wrapper.properties中的下载链接,使用与Android插件7.4.2对应的Gradle 7.5:

    distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
    
  3. 清理缓存并重建项目
    执行以下命令彻底清理缓存:

    flutter clean
    rm -rf ~/.gradle/caches
    flutter pub get
    flutter run
    
  4. 优化仓库配置(可选)
    若仍有问题,调整pluginManagement中仓库的顺序,确保google()优先:

    pluginManagement {
        // ... 原有代码 ...
        repositories {
            google()
            gradlePluginPortal()
            mavenCentral()
        }
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 20:38:10