I have this project in Flutter, but I haven't been able to build an apk for a couple of weeks, because of the Gradle version. I've tried everything, but Flutter always returns the error below:
I already install every update I found, even though, it shows that the Gradle version is 4.10.2.
flutter build 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.
Here some information about the project status and environment----------------------
Already changed gradle-wrapper.properties (Current file):
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(Current file):
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 --version
------------------------------------------------------------
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
flutter doctor -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!
Here is how I upgraded gradle in my older Flutter project:
Create a new temp project with the latest version of Flutter. You'll use this to see what version of gradle Flutter is using nowadays.
In the temp project open android/build.gradle check the classpath version of gradle being used and update that in your old Flutter project. For me today it looks like this:
classpath 'com.android.tools.build:gradle:4.1.0'
In the temp project open android/gradle/wrapper/gradle-wrapper.properties and check the distributionUrl. Update your old project to use the same one. For me today it looks like this:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
Rerun your app. It has to download the new version of gradle to the android/.gradle directory so the first time might take a while.
The easiest way (I do so as Android Dev):
Right click android folder in root folder
Flutter
Open in Android Studio
Wait for it to load completely
It'll ask you "Would you like to upgrade gradle?|"
Click Yes
flutter clean
android/gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
android/build.gradle:
classpath "com.android.tools.build:gradle:7.0.1"
in android/gradle.properties, add this:
org.gradle.java.home=C:\\Program Files\\Android\\Android Studio\\jre
It appears as if audioplayers has an incompatible gradle version with your project.
Try upgrading audioplayers to the newest version, although this may not fix the issue, as the last comment in this thread was less than 24 hours ago.
audioplayers: ^0.18.3
An update for 2022, Android Studio Dolphin. The other answers gave me a start, but are no longer up-to-date.
Open the main flutter project in Android Studio
Right click on the [android] module. Choose "Flutter". Choose Open Android module in Android Studio
I opened in a new window, but this probably isn't required.
As it says in the text here , choose on the menu (you must be in the "Android" project)
File
Project Structure
Project
Click the Android Gradle Plugin Version dropdown and choose the latest version (or whatever one you want to update to)
Click the Gradle Version dropdown and choose the latest version (or whatever one you want to update to)
Give time for your Gradle to sync (it might have to download quite a lot, so be patient)
Now you should be able to close the Android project window, and go back to the flutter project
Try renaming the android/ folder in your project. Then run flutter create . in the directory. This should recreate your android directory. Try your build again and see if it fixed your problem.
Upgrade gradle in a Flutter project.
Open the file gradle-wrapper.properties located at {yourProjectName}/android/gradle/wrapper/gradle-wrapper.properties and replace the distributionUrl by changing the gradle version.
For example if you want to upgrade gradle from version 5.1.1 to 6.1.1, change the Url from https\://services.gradle.org/distributions/gradle-5.1.1-all.zip to https\://services.gradle.org/distributions/gradle-6.1.1-all.zip and rebuild your app.
Fast way of doing it:
Open AndroidManifest.xml (andriod/app/src/main/AndroidManifest.xml)
Click "Open for Editing in Android Studio"
In late 2022, Android Studio can fix that and upgrade Gradle:
Open the main flutter project in Android Studio
Right click on the android module. Choose "Flutter". Choose Open Android module in Android Studio, I opened in a new window
Then, in the lower right corner, Android Studio presents a message suggesting to upgrade Gradle. Follow this suggestion!
After that, you can close the Android project window
Based on Nick Fortescue answer
I was getting this issue:
FAILURE: Build failed with an exception.
Where:
Build file '/home/marcelo-cesar/Desktop/Overseasconnection-player-teams/android/app/build.gradle' line: 47
What went wrong:
A problem occurred evaluating project ':app'.
Could not find method minSdkVersion() for arguments [19, null] on DefaultConfig$AgpDecorated_Decorated{name=main, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=com.ls.overseasagent, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=[], buildConfigFields={}, resValues={}, proguardFiles=[], consumerProguardFiles=[], manifestPlaceholders={applicationName=android.app.Application}, wearAppUnbundled=null} of type com.android.build.gradle.internal.dsl.DefaultConfig$AgpDecorated.
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 3s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
I solved it by making these changes:
In android/build.gradle
update these lines with these following:
ext.kotlin_version = '1.7.10'
classpath 'com.android.tools.build:gradle:7.3.1'
In android/app/build.gradle
update with this value:
compileSdkVersion 33
defaultConfig {
…
minSdkVersion 21
targetSdkVersion 31
}
In android/gradle/wrapper/gradle-wrapper.properties
update distribution line with this:
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
I get lot of errors when running command flutter run --release.
xxx#xxx-Inspiron-14-3467:~/Desktop/xxx$ flutter run --release
Multiple devices found:
SM A207F (mobile) • R9WMA0D0G7J • android-arm64 • Android 10 (API 29)
Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)
[0]: SM A207F (R9WMA0D0G7J)
[1]: Android SDK built for x86 (emulator-5554)
Please choose one: [0|1]: 0
Launching lib/main.dart on SM A207F in release mode...
Running Gradle task 'assembleRelease'...
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /home/xxx/Desktop/flutter_linux_1.20.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.2/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':connectivity:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> 1 exception was raised by workers:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/home/xxx/.gradle/caches/transforms-2/files-2.1/56399ec8cdc895aa561f5aa75e965d03/core-1.0.1/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/home/xxx/.gradle/caches/transforms-2/files-2.1/56399ec8cdc895aa561f5aa75e965d03/core-1.0.1/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.
* 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 3m 22s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 202.7s (!)
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the
incompatibility.
Building plugin connectivity...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done 2.0s
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'connectivity'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* 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
Exception: The plugin connectivity could not be built due to the issue above.
flutter doctor -v
xxx#xxx:~/Desktop/xxx$ flutter doctor -v
[✓] Flutter (Channel stable, 1.20.2, on Linux, locale en_US.UTF-8)
• Flutter version 1.20.2 at /home/xxx/Desktop/flutter_linux_1.20.2-stable/flutter
• Framework revision bbfbf1770c (3 weeks ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/xxx/Android/Sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Android Studio (version 3.5)
• Android Studio at /opt/android-studio
• Flutter plugin version 41.0.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.37.1)
• VS Code at /usr/share/code
• Flutter extension version 3.4.1
[✓] Connected device (2 available)
• SM A207F (mobile) • R9WMA0D0G7J • android-arm64 • Android 10 (API 29)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)
• No issues found!
What went wrong: A problem occurred configuring root project 'connectivity'.
The issue is came from connectivity plugin. After I upgraded to the latest version, it able to run now.
I created a new flutter project and when run it, it gives that error
Target kernel_snapshot failed: Exception: The value of -DDartDefines is not formatted correctly.
The value must be a JSON-encoded list of strings but was:
[flutter.inspector.structuredErrors=true]
build failed.
FAILURE: Build failed with an exception.
* Where:
Script 'D:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 882
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* 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
Exception: Gradle task assembleDebug failed with exit code 1
I have tried flutter clean, and same error
flutter doctor log :
D:\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel master, v1.16.4-pre.69, on Microsoft Windows [Version 10.0.18363.959], locale en-US)
• Flutter version 1.16.4-pre.69 at D:\flutter
• Framework revision 19e7db585d (4 months ago), 2020-04-01 11:16:01 -0700
• Engine revision c9506cb8e9
• Dart version 2.8.0 (build 2.8.0-dev.18.0 eea9717938)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\user\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.3
• 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)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[!] VS Code (version 1.47.2)
• VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
! No devices available
! Doctor found issues in 3 categories.
Process finished with exit code 0
According to what flutter doctor is giving you the problem might be related to Android Sdk not installed or not configured really well:
Flutter provides a command to update the Android SDK path: Use
flutter config --android-sdk <path-to-your-android-sdk-path>
You can install it directly from Android Studio:
To open the SDK Manager from Android Studio, click Tools > SDK Manager or click SDK Manager in the toolbar. You might have to uncheck "hide obsolete packages" and install the packages that were considered obsoletes.
Or you can install it from this link and configure it like I said before:
https://www.google.com/url?sa=t&source=web&rct=j&url=https://android-sdk.fr.uptodown.com/windows&ved=2ahUKEwi-itWCkuzqAhXTZTUKHa29CRMQFjACegQIAhAB&usg=AOvVaw1QSSVVMrZzFltXvboDbTeQ
Everytime i try to build an apk or appbundle, this error comes up. please help.
Warning! The 'flutter' tool you are currently running is from a different Flutter repository than the one last used by this package. The repository from which the 'flutter' tool is currently executing will be u
sed instead.
running Flutter tool: C:\Users\MOMO\Mygit\flutter
previous reference : C:\flutter
This can happen when you have multiple copies of flutter installed. Please check your system path to verify that you are running the expected version (run 'flutter --version' to see which flutter is on your pat
h).
Compiler message:
/C:/flutter/packages/flutter/lib/src/rendering/layer.dart:1580:36: Error: 'ImageFilterEngineLayer' isn't a type.
oldLayer: _engineLayer as ui.ImageFilterEngineLayer,
^^^^^^^^^^^^^^^^^^^^^^
/C:/flutter/packages/flutter/lib/src/rendering/layer.dart:1578:27: Error: The method 'pushImageFilter' isn't defined for the class 'SceneBuilder'.
'SceneBuilder' is from 'dart:ui'.
Try correcting the name to the name of an existing method, or defining a method named 'pushImageFilter'.
engineLayer = builder.pushImageFilter(
^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
Where:
Script 'C:\Users\MOMO\Mygit\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780
What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
Process 'command 'C:\Users\MOMO\Mygit\flutter\bin\flutter.bat'' finished with non-zero exit value 1
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
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 15.7s
Gradle task assembleRelease failed with exit code 1
Thats my flutter doctor -v
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.778], locale en-US)
• Flutter version 1.12.13+hotfix.9 at C:\Users\MOMO\Mygit\flutter
• Framework revision f139b11 (4 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\MOMO\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: D:\Android\Android Studio1\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at D:\Android\Android Studio1
• Flutter plugin version 45.0.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[√] IntelliJ IDEA Ultimate Edition (version 2019.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.1
• Flutter plugin version 45.0.2
• Dart plugin version 193.5731
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
Have been using Flutter with VSCode on Mac for months without issues, but suddenly flutter doctor produces this:
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.4 17E202, locale en-US)
• Flutter version 0.5.1 at [Path]/flutter
• Framework revision c7ea3ca377 (3 weeks ago), 2018-05-29 21:07:33 +0200
• Engine revision 1ed25ca7b7
• Dart version 2.0.0-dev.58.0.flutter-f981f09760
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at [Path]/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.3.1, Build version 9E501
• ios-deploy 1.9.2
• CocoaPods version 1.5.2
[✓] Android Studio (version 3.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 25.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[!] VS Code (version 1.24.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected devices (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
! Doctor found issues in 1 category.
I can confirm that flutter is installed, and nothing has changed since I started using it. Additionally, before I updated flutter (today), flutter doctor read, under VSCode, as:
[!] VS Code (version 1.24.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Dart Code extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code
However, post-upgrade that seems the inability to find dart might have been fixed.
There is a post from a few days ago here that indicates flutter doctor may just be inaccurate for the time being, so I tried to run the project, and got the following error stack:
Using hardware rendering with device Android SDK built for x86.
If you get graphics artifacts, consider enablingsoftware rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 2.0s
Resolving dependencies... 2.2s
Running 'gradlew assembleDebug'...
Error: unable to locate asset entry in pubspec.yaml:
"ios/Flutter/flutter_assets/fonts/MyFlutterApp.ttf".
Error building assets
FAILURE: Build failed with an exception.
* Where:
Script
'[Path]/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 435
* What went wrong:
Execution failed for task ':app:flutterBuildDebug'.
> Process 'command
'[Path]/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 17s
Gradle build failed: 1
MacBook-Pro-3:rambleapp TrentKennelly$ flutter trace
Error connecting to observatory: Exception: Attempted to connect to Dart
observatory 5 times, and all attempts failed. Giving up. The URL was
ws://127.0.0.1:8100/ws
Any thoughts on this?
There was a change in VSCode that broke extensions detection. It's safe to ignore this warning.
See the full comment of Danny Tuppeny, about this issue here.
For the stacktrace there are two things:
The asset "ios/Flutter/flutter_assets/fonts/MyFlutterApp.ttf"was
not found
The issue with obsvervatory
Did you check the asset still exists?
The project does not compile without it, and the observatory issue may be related to this.
Install the Flutter extension within VS Code.