Skip to content

Fix Source Value 8 is Obsolete Warning in Android Studio

Problem Statement

When working on Android projects in Android Studio, developers often encounter the warnings:

plaintext
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.

These warnings indicate that your project uses Java 8 as both the source and target compatibility version, which is now considered outdated. While the project currently compiles successfully, future Android Studio updates may drop support for this Java version altogether. Simply suppressing these warnings hides the underlying issue rather than addressing the root cause - the project is configured to use an obsolete Java version.

The optimal solution is to configure the Java toolchain in your Gradle setup. This approach sets a unified Java version for compilation and execution across your project:

groovy
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}
kotlin
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}

Key advantages:

  • Automatically sets sourceCompatibility, targetCompatibility, and Kotlin's jvmTarget consistently
  • Integrates with Gradle's build tool resolution
  • Minimizes configuration conflicts
  • Future-proof as Android tooling evolves

This solution works for both standard Android projects and Flutter projects.

TIP

This method requires Android Gradle Plugin (AGP) 8.0+ and Gradle 8.0+. Verify your versions:

  • gradle/wrapper/gradle-wrapper.properties:
    properties
    distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
  • build.gradle dependencies:
    groovy
    dependencies {
        classpath 'com.android.tools.build:gradle:8.3.2'
    }

Solution 2: Manual Compatibility Settings

For older projects or custom requirements, directly configure compatibility options:

groovy
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
}

This method is effective but requires maintaining consistent versions across multiple configuration points.

WARNING

If you're using Kotlin, you must set jvmTarget separately in kotlinOptions. Forgetting this is a common source of errors.

Complementary Configuration Steps

1. Verify JDK Installation

Ensure JDK 17 is installed and configured in Android Studio:

  1. FileProject StructureSDK Location
  2. Set JDK location to Java 17 (typically in /path/to/jdk-17)
  3. In Project section, set SDK to Android API <version>

2. Update Gradle Wrapper

In gradle/wrapper/gradle-wrapper.properties, use a compatible Gradle version:

properties
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

3. Update Plugin Versions

Ensure compatibility with your build scripts:

groovy
// In settings.gradle
pluginManagement {
    plugins {
        id "com.android.application" version "8.3.2"
        id "org.jetbrains.kotlin.android" version "2.0.20"
    }
}

Compatibility Matrix

ComponentRequired Version
JDK17
AGP8.0+
Kotlin Plugin1.9.20+
Gradle8.0+

Verifying Your Configuration

After making changes:

  1. Clean the project: BuildClean Project
  2. Invalidate caches: FileInvalidate Caches... → Select Invalidate and Restart
  3. Rebuild project: BuildRebuild Project

Confirm the warnings have disappeared in the Build Output pane.

Troubleshooting Tips

  • Android Studio fails to find JDK 17: Manually set path in build.gradle:
    groovy
    android {
        compileOptions {
            sourceCompatibility = JavaVersion.VERSION_17
            targetCompatibility = JavaVersion.VERSION_17
            // Path to your JDK 17
            sourceSets.main.java.srcDirs += "/path/to/jdk-17"
        }
    }
  • Plugin compatibility errors: Temporarily remove plugin versions from settings.gradle and let Gradle resolve compatible versions
  • Kotlin-Java mismatch: Ensure kotlinOptions.jvmTarget matches compileOptions.targetCompatibility

Why Updating Matters

Continuing to use outdated Java versions poses significant risks:

  • Security vulnerabilities in unsupported Java versions
  • Future Android Studio updates will drop support for Java 8
  • Missing modern language features and performance optimizations
  • Potential build failures in CI/CD environments

Official Guidance

The Android Developers documentation recommends using toolchain configuration as it ensures:

  • Consistency across build environments
  • Automatic JDK management
  • Compatibility with future Android tooling

By implementing either solutions presented in this article, you'll maintain an up-to-date development environment that aligns with current Android best practices and prevents future compatibility issues.