为何Flutter项目出现‘Could not resolve all files for configuration’错误?
解决“Could not resolve all files for configuration”错误的方案
错误信息
错误堆栈跟踪
ERROR:C:\Web Development\VS code\Flutter.projects\project1\build\path_provider_android\intermediates\runtime_library_classes_jar\debug\classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
错误详情
Execution failed for task ':app:mergeDexDebug'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Failed to transform classes.jar (project :path_provider_android) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, com.android.build.api.attributes.AgpVersionAttr=7.3.0, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.gradle.internal.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=19, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. > Execution failed for DexingWithClasspathTransform: C:\Web Development\VS code\Flutter.projects\project1\build\path_provider_android\intermediates\runtime_library_classes_jar\debug\classes.jar. > Error while dexing.
解决步骤
清理构建缓存
执行Flutter清理命令移除旧构建产物:flutter clean也可以手动删除项目根目录的
build文件夹,以及Android模块下的.gradle文件夹。更新依赖包
检查pubspec.yaml中path_provider的版本,替换为最新稳定版后执行:flutter pub get同步Gradle兼容配置
打开Android模块的build.gradle文件,确保AGP(版本7.3.0)与Gradle版本匹配(对应Gradle版本需在7.4-7.6区间)。修改后触发Gradle同步,重新下载依赖。临时禁用D8增量编译
在项目根目录的gradle.properties中添加以下配置:android.enableD8=false之后重新构建项目。
重新构建项目
完成上述操作后执行:flutter run --debug
内容的提问来源于stack exchange,提问作者Harsh .63
相关产品推荐
相关产品推荐

