Flutter: Response to Java 8 end-of-life
When developing an app using Flutter and attempting to run it, I encountered a warning in the console.
While the app runs without any issues, I decided to address the warning for long-term stability using the following method.
Issue
The following message appeared when running my app:
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
3 warnings
Cause
The message indicates that Java 8 is approaching its end-of-life and will no longer be supported soon.
In my Flutter project, generated by Android Studio, the issue arose because the default configuration compiles with Java 8.
You can check the support status of Java versions on the Oracle Java SE Support Roadmap.
Solution
To resolve this issue, you need to use a higher version of Java.
After some research, I found advice online suggesting modifications to the android/build.gradle file.
However, it appears that updates to Flutter have changed the required file and location.
Find and open the android\app\build.gradle file, then locate the following section:
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
Replace JavaVersion.VERSION_1_8 with a higher version as needed.
I updated it to version 17 as follows:
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17
}
For reference, VERSION_1_8 corresponds to Java version 1.8, often referred to simply as version 8.
Outcome
After rebuilding and running the app, the warning message no longer appears.