I have an error in my build.gradle file (android/build.gradle) in my Flutter project. The App is running completely normal but this error is still not looking good to me. Does anyone ever had this problem/error?


Here is my complete build.gradle file:
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
flutter doctor -v Output:
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.22598.200], locale de-DE)
• Flutter version 3.0.5 at C:\Flutter\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d570e (5 weeks ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\jjkla\AppData\Local\Android\sdk
• Platform android-31, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 2020.3)
• 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 11.0.10+0-b96-7249189)
[√] VS Code (version 1.70.1)
• VS Code at C:\Users\jjkla\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.46.0
[√] Connected device (2 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.81
• Edge (web) • edge • web-javascript • Microsoft Edge 104.0.1293.54
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
EDIT 1: Since this happened to me over a year ago now, I don't remember exactly what solved the error. But there was definitely an incompatible version with conflicted with another version. General Advice: You should take a look at your Kolin Version in android/build.gradle under ext.kotlin_version = 'x.x.x'. Take a look at the to find the Kotlin Website newest available Kolin Version.
Actually the problem is version mismatch ( java and gradle )
In my flutter project i faced the same problem, now i fix it.
Here is how?
First check your Java version run by this command javac --version
In my case my java version is 21 and then go to the Gradle's site now you can see the correct version that matches your java version
https://docs.gradle.org/current/userguide/compatibility.html
Then go to your flutter project directory, and then go to > android > gradle > gradle-wrapper.properties
In this file you can see distributionUrl like this
distributionUrl=https://services.gradle.org/distributions/gradle-8.4-all.zip
Then change the correct version that matches your java version.
for example instead of gradle-8.4-all.zip you can change you varsion and save the file and then reload window run flutter pub get
This will solve the problem
Same problem here, but in Linux and Visual Studio code.
With ./gradlew in android directory, the build failed due wrong Java version. Was Java 1.8, but must be at least 11. After update my java version, ./gradlew built successfully.
After restart visual studio code, the error was gone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With