Flutter Android build prints 'source value 7 is obsolete and will be removed'
warning: [options] source value 7 is obsolete and will be removed in a future releaseShort answer
The warning comes from javac, not Flutter. Some Gradle module compiles Java with an old language level, and the JDK running the build is newer. If the module is yours, set sourceCompatibility and targetCompatibility to 17. If it is a plugin you do not own, hide the options lint for that task.
Fix it fast
1Find out which cause you have
Run a verbose Gradle build so the warning appears with the task that printed it. The task name, such as :some_plugin:compileDebugJavaWithJavac, shows which module owns the old setting.
cd android ./gradlew app:assembleDebug --warning-mode all2Match what you see, then jump to its fix
What does the error look like?
warning: [options] source value 7 is obsolete and will be removed in a future releasewarning: [options] target value 7 is obsolete and will be removed in a future releasewarning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
Cause 1 of 2
Your own module sets an old Java level
1Check
Open android/app/build.gradle and look at compileOptions. sourceCompatibility defaults to the Java toolchain, or to a version the Android Gradle Plugin picks, when you leave it out.
grep -n -A4 compileOptions android/app/build.gradle*2Fix
Set both values explicitly. Android's docs recommend the same value for both, and targetCompatibility must be equal to or higher than sourceCompatibility.
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}3Verify
Rebuild and check that the warning for :app is gone.
cd android
./gradlew app:assembleDebugConfirmed by developer.android.com
Cause 2 of 2
A plugin or library you do not own compiles with the old level
1Check
First try updating the plugin to a newer release that raised its level.
flutter pub outdated2Fix
Update the plugin. If no update exists, the warning is harmless and can be hidden for all Java tasks with the options lint key, which javac documents under -Xlint. Add this to android/build.gradle.
subprojects {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.add("-Xlint:-options")
}
}3Verify
Rebuild; the [options] lines no longer print.
cd android
./gradlew app:assembleDebugConfirmed by docs.oracle.com
How do I stop it coming back?
- Set sourceCompatibility and targetCompatibility in every module you own.
- Keep plugins current with flutter pub outdated.
- Read the task name in a warning before editing any build file.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Flutter release build cannot open the keystore: HmacPBESHA256 not available
Algorithm HmacPBESHA256 not available
The keystore is a PKCS12 file protected by a newer algorithm than the Java that is reading it understands.
3 causes, each with a fixMobile apps
Flutter Android build fails: Java is too new for this Gradle version
Unsupported class file major version 61
Gradle only runs on Java versions it knows.
3 causes, each with a fixMobile apps
Flutter Android: Failed to load FirebaseOptions from resource
Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json.
4 causes, each with a fixMobile apps
Flutter Android build stops with Execution failed for task ':app:…'
Execution failed for task ':app:compileFlutterBuildRelease'.
The line only tells you which Gradle step broke; the task name in the quotes tells you why.
5 causes, each with a fixMobile apps
Flutter's Android build stops: JAVA_HOME is not set
ERROR: JAVA_HOME is set to an invalid directory
The Gradle wrapper script needs a Java runtime and looks in two places: the JAVA_HOME variable, then a java command on PATH.
3 causes, each with a fixMobile apps
flutter_local_notifications crashes on Android with Integer.intValue() on a null object reference
NullPointerException in setSmallIcon
The crash comes from the small icon.
2 causes, each with a fix