skip to Main Content

I’m currently 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.

Could someone please guide me on how to update the Java source and target compatibility in my project, or if there’s another way to suppress these warnings?

Thank you

2

Answers


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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search