Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

javac warns that source value 8 is obsolete in an Android build

Error[options] source value 8 is obsolete and will be removed in a future release

Short answer

The warning means the build asks a newer JDK to compile Java at language level 8. Raise sourceCompatibility and targetCompatibility to 17 (or set a toolchain), or, if you must stay on 8, pass -Xlint:-options to javac so only that category is hidden.

  • Applies to Android Gradle Plugin 8.x, Gradle 8.x, JDK 17 and newer
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find where the Java level is set. It is either in compileOptions of the Android module or inherited from the toolchain.

    grep -rnE "sourceCompatibility|targetCompatibility|toolchain|VERSION_1_8" app/build.gradle* build.gradle*
  2. 2Match what you see, then jump to its fix

    1. 1VERSION_1_8 appears in compileOptionscompileOptions still asks for Java 8Fix
    2. 2A java module (not the Android app) prints the warningA toolchain or release flag in a plain Java module sets 8Fix
    3. 3A library or minSdk forces level 8 and the warning is the only problemYou must stay on Java 8 and only want the warning goneFix

What does the error look like?

  • [options] source value 8 is obsolete and will be removed in a future release

Cause 1 of 3

compileOptions still asks for Java 8

1Check

sourceCompatibility sets which Java language features are available; targetCompatibility sets the bytecode version. Both default to the toolchain version when you do not set them.

grep -n "VERSION_1_8" app/build.gradle app/build.gradle.kts 2>/dev/null

2Fix

Set both to the same newer level, and keep targetCompatibility at or above sourceCompatibility. Check that your minSdk supports the features you start using.

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}

3Verify

Rebuild and look for the warning in the compile output.

./gradlew :app:compileDebugJavaWithJavac

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

A toolchain or release flag in a plain Java module sets 8

1Check

Gradle recommends a toolchain, plus options.release when you cross-compile to an older level, and says sourceCompatibility and targetCompatibility should be avoided where toolchains work.

grep -rn "release" --include=build.gradle* .

2Fix

Pin the toolchain and the release level in the module build file.

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}
tasks.withType<JavaCompile>().configureEach {
    options.release = 17
}

3Verify

Run the compile task again.

./gradlew compileJava

Confirmed by docs.gradle.org

Did this fix it?

Cause 3 of 3

You must stay on Java 8 and only want the warning gone

1Check

The javac options lint category covers warnings about command-line options. A key preceded by a hyphen disables that warning.

./gradlew :app:compileDebugJavaWithJavac --info | grep -i options

2Fix

Pass -Xlint:-options to javac. It hides this category only; other warnings stay.

tasks.withType<JavaCompile>().configureEach {
    options.compilerArgs.add("-Xlint:-options")
}

3Verify

Rebuild; the [options] lines should be gone.

./gradlew :app:compileDebugJavaWithJavac

Confirmed by docs.oracle.com

Did this fix it?

How do I stop it coming back?

  • Set the Java level in one place and keep the toolchain version equal to it.
  • Do not mix --release with -source or -target; javac rejects the combination.
  • Plan the move off level 8 instead of hiding the warning for good.

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:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Mobile apps

adb tcpip 5555 fails because no device is found

adb: more than one device/emulator

adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.