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代码块属于误用,因此触发报错。
解决步骤
- 移除
pluginManagement块内的dependencies代码块 - 将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
相关产品推荐
相关产品推荐

