文章目录
一、 报错信息
二、 问题分析
三、 解决方案
一、 报错信息
问题环境描述 : 在 电脑 A 上创建了 Flutter 应用 , 上传到了 GitHub 中 , 然后在 电脑 B 上下载该源码 , 编译时报如下错误 ;
FAILURE: Build failed with an exception. * Where: Settings file 'D:\002_Project\002_Android_Learn\flutter_photo\android\settings.gradle' line: 11 * What went wrong: A problem occurred evaluating settings 'android'. > Could not read script 'D:\001_Programs\004_Flutter\flutter\packages\flutter_tools\gradle\app_plugin_loader.gradle' as it does not exist. * 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 1s Running Gradle task 'assembleRelease'... 3.1s Gradle task assembleRelease failed with exit code 1 Process finished with exit code 1
二、 问题分析
问题核心错误 :
Could not read script 'D:\001_Programs\004_Flutter\flutter\packages\flutter_tools\gradle\app_plugin_loader.gradle' as it does not exist.
编译时需要 D:\001_Programs\004_Flutter\flutter\packages\flutter_tools\gradle\app_plugin_loader.gradle 文件 , 我在 D:\001_Programs\004_Flutter\flutter\packages\flutter_tools\gradle\ 目录下没有找到 app_plugin_loader.gradle 文件 ;
查看该出现问题的 android/setting.gradle 文件 ;
include ':app' def localPropertiesFile = new File(rootProject.projectDir, "local.properties") def properties = new Properties() assert localPropertiesFile.exists() localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } def flutterSdkPath = properties.getProperty("flutter.sdk") assert flutterSdkPath != null, "flutter.sdk not set in local.properties" apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
在本电脑上可运行的其它应用的 android/setting.gradle 文件 ;
include ':app' def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() def plugins = new Properties() def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } plugins.each { name, path -> def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() include ":$name" project(":$name").projectDir = pluginDirectory }
电脑 B 上创建的 Flutter 工程可以在 电脑 A 上运行 ;
电脑 A 上创建的 Flutter 工程不能在 电脑 B 上运行 ;
怀疑是环境版本 , Flutter 版本 , Dart 版本 , Android Studio 版本 , Android SDK 版本 不一致导致的 ;
建议全部使用相同的配置 ;