首页 > 解决方案 > FAILURE:构建失败并出现异常(共享首选项和 gradle 包装器属性)

问题描述

当我在终端上运行 flutter run --release 命令时出现此错误。请帮助我解决这个问题,并让我知道我在哪里做错以使其成功发布。

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\flutter\.pub-cache\hosted\pub.dartlang.org\shared_preferences_macos-0.0.1+2\android\build.gradle' line: 22

* What went wrong:
A problem occurred evaluating root project 'shared_preferences_macos'.
> Failed to apply plugin [id 'com.android.library']
   > Minimum supported Gradle version is 5.4.1. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in C:\flutter\.pub-cache\hosted\pub.dartlang.org\s
hared_preferences_macos-0.0.1+2\android\gradle\wrapper\gradle-wrapper.properties to gradle-5.4.1-all.zip

* 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


The plugin shared_preferences_macos could not be built due to the issue above.

这是我的颤振医生:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18362.535], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 3.5)
[√] Connected device (1 available)

• No issues found!

我还将我的 gradle 包装器属性更新为这个,但遇到了同样的问题

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

标签: flutterdartbuild.gradlesharedpreferencesrelease

解决方案


感谢@umair 的解决方案。让我简要介绍一下解决方案。

我们必须在显示错误的各个插件的 gradle-wrapper.properties 文件中更新版本。

假设如果“shared_preferences_macos”显示错误,那么我们必须从下面的路径更新“shared_preferences_macos”插件的 gradle-wrapper.properties文件中的版本号。

路径: /Users/admin/Library/Android/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+3/android/gradle/wrapper/gradle-wrapper.properties

从上面的路径中,我们必须打开 gradle-wrapper.properties文件,并且必须在distributionUrl变量中将版本从 4.10.2 更新到 5.4.1并保存文件。而已。

笔记:

  • 相应插件的 gradle-wrapper.properties 文件的路径将显示在您的终端错误消息中
  • 建议的 Gradle 版本也将显示在您的终端错误消息中
  • 对您遇到错误消息的所有插件重复相同的过程。

推荐阅读