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

Gradle报错:pluginManagement中无dependencies()方法,求替代方案

解决Flutter项目settings.gradle中pluginManagement块dependencies()方法报错问题

报错信息

Could not find method dependencies() for arguments [settings_cn0h89kgygs6v1tnoowf6zgq6$_run_closure1$_closure5@45f4580] on object of type org.gradle.plugin.management.internal.DefaultPluginManagementSpec.

问题原因

Gradle的pluginManagement配置块仅负责管理插件仓库、插件版本等插件相关的全局配置,不支持通过dependencies()方法声明类路径依赖,你在该块中定义dependencies代码块属于误用,因此触发报错。

解决步骤

  1. 移除pluginManagement块内的dependencies代码块
  2. 将R8的classpath依赖转移到项目根目录的build.gradle文件的buildscript块中

修改后的代码示例

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
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
        maven {
            url = uri("https://storage.googleapis.com/r8-releases/raw")
        }
    }
    // 已移除原有的dependencies代码块
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.2"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}

include ":app"

2. 根目录build.gradle的补充配置

在项目根目录的build.gradle中添加(或修改)buildscript块,声明R8依赖:

buildscript {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://storage.googleapis.com/r8-releases/raw")
        }
    }
    dependencies {
        classpath("com.android.tools:r8:8.2.24")
    }
}

// 保留项目原有的其他配置,例如:
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
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 07:22:38