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:
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.
Recommended Solutions
Solution 1: Modern Approach Using Java Toolchain (Recommended)
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:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
Key advantages:
- Automatically sets
sourceCompatibility
,targetCompatibility
, and Kotlin'sjvmTarget
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
:propertiesdistributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
build.gradle
dependencies:groovydependencies { classpath 'com.android.tools.build:gradle:8.3.2' }
Solution 2: Manual Compatibility Settings
For older projects or custom requirements, directly configure compatibility options:
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:
- File → Project Structure → SDK Location
- Set JDK location to Java 17 (typically in
/path/to/jdk-17
) - In Project section, set SDK to Android API <version>
2. Update Gradle Wrapper
In gradle/wrapper/gradle-wrapper.properties
, use a compatible Gradle version:
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:
// In settings.gradle
pluginManagement {
plugins {
id "com.android.application" version "8.3.2"
id "org.jetbrains.kotlin.android" version "2.0.20"
}
}
Compatibility Matrix
Component | Required Version |
---|---|
JDK | 17 |
AGP | 8.0+ |
Kotlin Plugin | 1.9.20+ |
Gradle | 8.0+ |
Verifying Your Configuration
After making changes:
- Clean the project: Build → Clean Project
- Invalidate caches: File → Invalidate Caches... → Select Invalidate and Restart
- Rebuild project: Build → Rebuild 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
:groovyandroid { 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
matchescompileOptions.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.