Reputation: 1173
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.
Upvotes: 17
Views: 35061
Reputation: 1
try this in the command with internet connection then restart vscode
flutter clean
flutter pub get
cd android
./gradlew clean
Upvotes: 0
Reputation: 63
If you followed every single answer yet, the error still persists. Make sure that the version of JDK that you are using supports or is compatible with a particular version of Gradle. For more information, check here: compatibility
Upvotes: 0
Reputation: 36
These are the step I handle above error.
first check errors in flutter:
flutter doctor
then rebuld build.gradle:
cd android
./gradlew clean
./gradlew build
./gradlew clean build
Optional tasks:
flutter upgrade
flutter pub get
then restart the IDE and check.
Upvotes: 0
Reputation: 1
For me it was definitely related to the java version, installing java 11 and giving the correct JAVA_HOME path in Environment Variables and restarting the computer eliminated the problem
Upvotes: 0
Reputation:
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
Upvotes: 11
Reputation: 1
You can try to install java 11 version or higher. Download java 11 version install it on your system > restart vs code or whichever code editor you are using > in terminal you can run flutter clean and then run flutter pub get
Make the following changes to your build.gradle file:
Upvotes: 0
Reputation: 116
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.
Upvotes: 7
Reputation: 21
I tried to open Android directory (which is in my flutter project) with Android studio, Android studio suggested to upgrade and then I followed suggestion, and finally error is solved now.
Upvotes: 2
Reputation: 2833
This error can be occurred if you change the name of your app under pubspec.yaml
file
you can resolve this error by two ways
reverting the previous name
Going under projects build.gradle
file and change this
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
to
subprojects {
project.buildDir = "${rootProject.buildDir}/Groic"
}
we've changed project.name
with the name mentioned in pubspec.yaml
Upvotes: 0
Reputation: 1693
You can try to rebuild the build.gradle
file.
Just follow these steps.
cd android
./gradlew clean
./gradlew build
You can also execute this command in one line.
./gradlew clean build
Upvotes: 1
Reputation: 2425
You can do flutter clean and flutter pub get and then try to build again.
Upvotes: 1
Reputation: 136
open your android project in android studio file > open > in your flutter project choose android file then rebuild gradle, I have same problem and solved it like this.
Upvotes: 0