文章目录
- 一、 报错信息
- 二、 问题分析
- 三、 解决方案
一、 报错信息
问题环境描述 : 在 电脑 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 版本 不一致导致的 ;
建议全部使用相同的配置 ;
三、 解决方案
删除源码中的 android 目录 , 整个删除 , 然后在 Terminal 中进入 源码根目录 , 执行
flutter create .
命令 , 就会重新生成 android 目录 ;
命令行打印数据如下 : flutter_photo 就是源码的根目录 ;
D:\002_Project\002_Android_Learn\flutter_photo>flutter create .
Recreating project ....
.idea\libraries\Flutter_for_Android.xml (created)
.idea\libraries\KotlinJavaRuntime.xml (created)
.idea\runConfigurations\main_dart.xml (created)
android\app\build.gradle (created)
android\app\src\main\kotlin\com\example\flutter_photo\MainActivity.kt (created)
android\build.gradle (created)
android\flutter_photo_android.iml (created)
android\.gitignore (created)
android\app\src\debug\AndroidManifest.xml (created)
android\app\src\main\AndroidManifest.xml (created)
android\app\src\main\res\drawable\launch_background.xml (created)
android\app\src\main\res\mipmap-hdpi\ic_launcher.png (created)
android\app\src\main\res\mipmap-mdpi\ic_launcher.png (created)
android\app\src\main\res\mipmap-xhdpi\ic_launcher.png (created)
android\app\src\main\res\mipmap-xxhdpi\ic_launcher.png (created)
android\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png (created)
android\app\src\main\res\values\styles.xml (created)
android\app\src\profile\AndroidManifest.xml (created)
android\gradle\wrapper\gradle-wrapper.properties (created)
android\gradle.properties (created)
android\settings.gradle (created)
flutter_photo.iml (created)
Wrote 25 files.
All done!
[√] Flutter: is fully installed. (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.1139], locale zh-CN)
[√] Android toolchain - develop for Android devices: is fully installed. (Android SDK version 29.0.3)
[√] Android Studio: is fully installed. (version 4.0)
[!] IntelliJ IDEA Community Edition: is partially installed; more components are available. (version 2019.3)
[√] Connected device: is fully installed. (1 available)
Run "flutter doctor" for information about installing additional components.
In order to run your application, type:
$ cd .
$ flutter run
Your application code is in .\lib\main.dart.
D:\002_Project\002_Android_Learn\flutter_photo>
然后编译运行 , 成功 ;