首次运行Flutter新项目时出现org.codehaus.groovy依赖缺失错误
Flutter首次运行Gradle依赖解析错误解决方案
首次运行新Flutter应用时,出现Gradle无法解析Groovy系列依赖的错误,所有Groovy包的版本占位符显示为?.?.??,已尝试重装Flutter SDK、flutter doctor检测无异常,但问题未解决。
错误日志如下:
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode... FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':gradle:compileGroovy'. > Could not resolve all files for configuration ':gradle:detachedConfiguration1'. > Could not find org.codehaus.groovy:groovy:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy/?.?.??/groovy-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/?.?.??/groovy-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-ant:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-ant/?.?.??/groovy-ant-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-ant/?.?.??/groovy-ant-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-astbuilder:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-astbuilder/?.?.??/groovy-astbuilder-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-astbuilder/?.?.??/groovy-astbuilder-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-console:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-console/?.?.??/groovy-console-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-console/?.?.??/groovy-console-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-datetime:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-datetime/?.?.??/groovy-datetime-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-datetime/?.?.??/groovy-datetime-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-dateutil:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-dateutil/?.?.??/groovy-dateutil-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-dateutil/?.?.??/groovy-dateutil-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-nio:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-nio/?.?.??/groovy-nio-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-nio/?.?.??/groovy-nio-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-sql:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-sql/?.?.??/groovy-sql-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-sql/?.?.??/groovy-sql-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-test:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-test/?.?.??/groovy-test-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-test/?.?.??/groovy-test-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-templates:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-templates/?.?.??/groovy-templates-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-templates/?.?.??/groovy-templates-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-json:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-json/?.?.??/groovy-json-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-json/?.?.??/groovy-json-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-xml:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-xml/?.?.??/groovy-xml-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-xml/?.?.??/groovy-xml-?.?.??.pom Required by: project :gradle > Could not find org.codehaus.groovy:groovy-groovydoc:?.?.??. Searched in the following locations: - https://dl.google.com/dl/android/maven2/org/codehaus/groovy/groovy-groovydoc/?.?.??/groovy-groovydoc-?.?.??.pom - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-groovydoc/?.?.??/groovy-groovydoc-?.?.??.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 14s Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm)
解决步骤:
- 检查Gradle版本配置:打开项目
android/gradle/wrapper/gradle-wrapper.properties文件,确认distributionUrl指向稳定的Gradle版本,例如https\://services.gradle.org/distributions/gradle-8.4-all.zip(需与当前Flutter版本兼容) - 配置镜像源(针对网络访问问题):编辑
android/build.gradle,在buildscript和allprojects的repositories块中添加国内镜像,示例:buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } mavenCentral() } } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } mavenCentral() } } - 清除Gradle缓存:删除用户目录下的
.gradle文件夹(Windows路径:C:\Users\<用户名>\.gradle;Mac/Linux路径:~/.gradle),之后重新执行flutter run - 确认JDK配置:确保
JAVA_HOME环境变量指向Android Studio自带的Embedded JDK,避免版本不兼容问题 - 重建测试项目:使用
flutter create test_app生成全新项目,尝试运行以排查原项目配置异常
内容的提问来源于stack exchange,提问作者Ramez Sleem
相关产品推荐
相关产品推荐

