我在Flutter中有一个项目,但由于Gradle版本的原因,我已经有几周无法构建apk了。我尝试了所有方法,但Flutter总是返回以下错误:
我已经安装了我找到的每一个更新,尽管它显示Gradle版本是4. 10. 2。
- Flutter建立APK
...
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\israel.gomes\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.4\android\build.gradle' line: 25
* What went wrong:
A problem occurred evaluating root project 'audioplayers'.
> Failed to apply plugin [id 'kotlin-android']
> The current Gradle version 4.10.2 is not compatible with the Kotlin Gradle plugin. Please use Gradle 5.3 or newer, or the previous version of the Kotlin plugin.
* 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
The plugin audioplayers could not be built due to the issue above.
这里介绍一些关于项目现状和环境的信息--------------
- 已更改 gradle-wrapper.properties(当前文件):
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
- android/build.gradle(当前文件):
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
.
.
.
- Gradle版本
------------------------------------------------------------
Gradle 5.6.2
------------------------------------------------------------
Build time: 2019-09-05 16:13:54 UTC
Revision: 55a5e53d855db8fc7b0e494412fc624051a8e781
Kotlin: 1.3.41
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM: 1.8.0_261 (Oracle Corporation 25.261-b12)
OS: Windows 10 10.0 amd64
- 颤动医生-v
[√] Flutter (Channel dev, 2.1.0-12.1.pre, on Microsoft Windows [versão 10.0.19042.867], locale pt-BR)
• Flutter version 2.1.0-12.1.pre at C:\Flutter
• Framework revision 8264cb3e8a (3 weeks ago), 2021-03-10 12:37:57 -0800
• Engine revision 711ab3fda0
• Dart version 2.13.0 (build 2.13.0-116.0.dev)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\israel.gomes\AppData\Local\Android\Sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = C:\Users\israel.gomes\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] IntelliJ IDEA Community Edition (version 2020.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3
• Flutter plugin version 55.0.4
• Dart plugin version 203.7759
[√] VS Code (version 1.54.3)
• VS Code at C:\Users\israel.gomes\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.20.0
[√] Connected device (3 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.114
• Edge (web) • edge • web-javascript • Microsoft Edge 87.0.664.75
• No issues found!
8条答案
按热度按时间agyaoht71#
下面是我如何在我的旧Flutter项目中升级gradle:
1.使用Flutter的最新版本创建一个新的临时项目。您将使用此项目查看Flutter目前使用的Gradle版本。
1.在临时项目中打开android/build.gradle,检查正在使用的gradle的类路径版本,并在旧的Flutter项目中更新该版本。
1.在临时项目中,打开android/gradle/wrapper/gradle-wrapper.properties并检查
distributionUrl
。更新旧项目以使用相同的项目。对我来说,今天的项目如下所示:1.重新运行您的应用。它必须将新版本的gradle下载到
android/.gradle
目录,因此第一次运行可能需要一段时间。camsedfj2#
最简单的方法(我是以Android Dev的身份这么做的):
1.右键单击根文件夹中的android文件夹
1.扑动
1.在Android Studio中打开
1.等待它完全加载
1.它会询问您“是否要升级gradle?|“
1.单击“是”
flutter clean
z0qdvdin3#
看起来好像
audioplayers
的gradle版本与您的项目不兼容。请尝试将
audioplayers
升级到最新版本although this may not fix the issue, as the last comment in this thread was less than 24 hours ago。35g0bw714#
android/gradle/wrapper/gradle-wrapper.properties
:android/build.gradle
:在
android/gradle.properties
中,添加以下内容:ruarlubt5#
尝试重命名项目中的
android/
文件夹。然后在目录中运行flutter create .
。这将重新创建您的android目录。再次尝试构建,看看它是否修复了您的问题。6tr1vspr6#
升级Flutter项目中的gradle。打开位于
{yourProjectName}/android/gradle/wrapper/gradle-wrapper.properties
的文件gradle-wrapper.properties
,并通过更改gradle
版本来替换distributionUrl
。例如,如果您要将gradle从版本
5.1.1
升级到6.1.1
,请将URL从https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
更改为https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
,然后重新构建您的应用。exdqitrt7#
快速方法:
1.打开Android信息清单. xml文件(android/app/src/main/Android信息清单. xml文件)
1.点击“在Android Studio中打开以进行编辑”
p8h8hvxi8#
Android Studio海豚是2022年的更新。其他的答案让我有了一个开始,但已经不再是最新的了。
1.在Android Studio中打开主flutter项目
1.右击[android]模块。选择“Flutter”。选择
Open Android module in Android Studio
1.我在新窗口中打开,但这可能不是必需的。
File
个Project Structure
Project
Android Gradle Plugin Version
下拉菜单并选择最新版本(或您要更新到的任何版本)Gradle Version
下拉菜单并选择最新版本(或您要更新到的任何版本)