I am currently working on a flutter repository and whenever I start the repository it gives me an error:
Can't use Java 21.0.1 and Gradle 8.1.1 to import Gradle project android.
How should I fix this thing?
Since the program was running I didn't try anything new.
It seems like you are encountering an issue related to Java and Gradle versions while working on a Flutter repository. The error suggests that there is a compatibility issue between Java 21.0.1 and Gradle 8.1.1 for importing the Gradle project in Android.
To resolve this issue, you can try the following steps:
Check Flutter and Dart SDK versions: Ensure that your Flutter and Dart SDK versions are compatible with the Java and Gradle versions you are using. You can check the Flutter documentation or release notes for compatibility information.
Update Gradle Version:
Update the Gradle version used in your Flutter project. You can do this by modifying the android/build.gradle
file. Change the classpath
in the dependencies
block to use a version that is compatible with your Java version. For example:
dependencies {
classpath com.android.tools.build:gradle:4.1.1
}
Update Java Version:
Ensure that your Flutter project is configured to use a Java version compatible with the Gradle version. Update the Java version in your projects android/app/build.gradle
file:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Check Flutter Channel:
Ensure that you are on a Flutter channel that supports the versions of Java and Gradle you are using. You can switch Flutter channels using the flutter channel
command.
Update Flutter: Make sure you are using the latest version of Flutter by running the following commands:
bashflutter channel stable
flutter upgrade
After making these changes, try running your Flutter project again. If the issue persists, you may need to adjust the Java and Gradle versions further to find a compatible combination.