Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: [options] source value 7 is obsolete and will be removed in a future release

I get the ff error when i run flutter run.

warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
error: warnings found and -Werror specified

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':connectivity:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

This is my flutter doctor output:

[√] Flutter (Channel stable, 1.20.4, on Microsoft Windows [Version 10.0.18362.1139], locale en-US)
    • Flutter version 1.20.4 at C:\src\flutter
    • Framework revision fba99f6cf9 (8 weeks ago), 2020-09-14 15:32:52 -0700
    • Engine revision d1bc06f032
    • Dart version 2.9.2


[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\USER01\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\PROGRA~1\Java\jdk-13.0.2\bin\java
    • Java version Java(TM) SE Runtime Environment (build 13.0.2+8)
    • All Android licenses accepted.

I cant seem to find anything on google. How do i fix this error ?

like image 645
marvin ralph Avatar asked Nov 11 '20 17:11

marvin ralph


3 Answers

This is a warning about the compiler targeting an older version of Java (7 in this case) that will be deprecated soon.

To fix this you have two options:

  1. You can set your JAVA_HOME to an older version of Java and then run your Flutter build. You would also need to have this JAVA_HOME available anywhere you build from (command line, IDE, CI/CD, etc)
  2. Or my preferred way is to tell Gradle to use an older Java toolchain for compiling Java source.

To do option 2, update your allprojects section of android/build.gradle to look like the following:


allprojects {
  repositories {
    google()
    mavenCentral()
  }

  tasks.withType(JavaCompile).configureEach {
    javaCompiler = javaToolchains.compilerFor {
      languageVersion = JavaLanguageVersion.of(8)
    }
  }
}

This includes an update to change the deprecated jcenter Maven repository.

EDIT Nov 2021: Support for toolchains has also been added to the Kotlin Gradle plugin.

https://blog.jetbrains.com/kotlin/2021/11/gradle-jvm-toolchain-support-in-the-kotlin-plugin/

like image 154
Shane Avatar answered Sep 22 '22 12:09

Shane


Try doing this Android Studio -> File -> Invalid cache and restart

like image 40
Priyaank Avatar answered Sep 22 '22 12:09

Priyaank


This is not a fix but a temporary workaround. Put the following in your build.gradle, under the allprojects{} section:

tasks.withType(JavaCompile) {
    options.compilerArgs << '-Xlint:-options' 
}

If your Android java code is the unmodified default generated code, then the bug is with one of your dependencies, you will have to go through pubspec.yaml and find the library that is causing the error.

like image 33
user3551708 Avatar answered Sep 19 '22 12:09

user3551708