Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve "source value 8 is obsolete" warning in Android Studio?

I'm working on an Android project in Android Studio and I'm getting the following 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.

I understand that these warnings are related to the Java version being used, but I'm not sure how to update the source and target values to fix this issue.

How to update the Java source and target compatibility in my project? Or is there another way to suppress these warnings?

like image 826
Faiz Ahmad Dae Avatar asked Sep 06 '25 03:09

Faiz Ahmad Dae


2 Answers

I recently faced the exact issue while working on my Flutter project, and after two days of troubleshooting, I found a solution that worked for me. The problem stems from an incompatibility between the Java Development Kit (JDK) version and the Gradle configuration. Here’s how I resolved it:

  1. Downgrade the JDK to Version 17

Flutter projects currently work best with JDK 17 for the latest Gradle and Android plugin versions. You can download JDK 17 from the official OpenJDK website. JDK 17 - Setup file

  1. Update app/build.gradle

Ensure that the compileOptions and kotlinOptions target JDK 17:

android {
    ndkVersion "25.1.8937393"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
}
  1. Update gradle/wrapper/gradle-wrapper.properties

Set the distributionUrl to a compatible Gradle version, such as 8.10.2:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
  1. Update settings.gradle

Ensure the plugin versions are compatible with JDK 17 and Gradle 8.3.2:

id "com.android.application" version "8.3.2" apply false
id "org.jetbrains.kotlin.android" version "2.0.20" apply false

I struggled with these warnings for two days before discovering the solution. It wasn’t immediately clear that the issue lay in the mismatch between Java, Gradle, and plugin versions. By systematically adjusting configurations and testing, I was able to eliminate the warnings and build my project successfully.

If you’re facing similar issues, I hope this solution saves you time and frustration! Let me know if you encounter any challenges implementing these changes.

like image 100
Sayed Mohammad Sadat Avatar answered Sep 08 '25 00:09

Sayed Mohammad Sadat


Read The Fine Manual.

In build.gradle put:

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

If using build.gradle.kts, put:

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

Doing either supplies defaults for sourceCompatibility and targetCompatibility.

like image 45
Basil Bourque Avatar answered Sep 07 '25 23:09

Basil Bourque