102

When I build my Android project in Android Studio, I get message:

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

and

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

I would like to do what the message suggested, but how? How can I configure my Android studio to re-compile my project with -Xlint as the above message suggested? (I am using Android Studio 3.0.1)

lcnicolau
  • 3,252
  • 4
  • 36
  • 53
Leem
  • 17,220
  • 36
  • 109
  • 159
  • Have you check this link https://stackoverflow.com/questions/197986/what-causes-javac-to-issue-the-uses-unchecked-or-unsafe-operations-warning – Mitesh Vanaliya Dec 10 '17 at 16:26
  • @MiteshVanaliya, the link is unrelated with my question. I am asking how to do what the message suggested with Android Studio, not how to get rid of this message. – Leem Dec 10 '17 at 16:35

6 Answers6

174

The message suggest you recompile with args -Xlint to get more warning details, add these code to build.gradle:

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
}

Then you can fix warnings by detailed messages.
For example, you can replace deprecated method with new method(there always been a new method since old method has been deprecated) .

However, sometimes we don't want change our code for some reasons, we just want get rid of compile warning, you can add @SuppressWarnings("deprecation") in front of the deprecated method.

y4n9b0
  • 1,899
  • 1
  • 7
  • 6
  • Working with me. Thanks – JeanCarlos Chavarria Oct 21 '19 at 22:36
  • While this answer works it didn't help me at all, I've received 63 deprecation warnings. This company should hire someone who does nothing else all day but check what's been changed in android and rewrite the code accordingly. – soger Aug 23 '21 at 09:49
  • I do not want to fix the warnings blindly, but see them. How can I see the warnings. – Andrew S Mar 22 '22 at 17:55
  • What if the deprecated item is in generated code? How can I Suppress it then? Any ideas? – mal Jul 03 '23 at 13:42
12

You need to add the following inside your app level buld.graddle file

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
}

If for some reasons you need to continue using a deprecated API you can just suppress the warning. You could annotate the deprecated method with the

@SuppressWarnings("deprecation")

annotation.

post link

Vahag Chakhoyan
  • 873
  • 1
  • 10
  • 21
6

If you are facing issue in generating signed apk, you can try to do this in your build.gradle(app)

android {
    lintOptions {
        checkReleaseBuilds false
    }
}
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
3

It is some error in the project, maybe from XML files. Disabling lintOptions is not a correct solution. Find the error and fix the problem, to do this run below command in Android Studio Terminal

Windows

gradlew assembleDebug --stacktrace

MAC

./gradlew assembleDebug --stacktrace

Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74
0

You can manually run configured lint and other IDE inspections by selecting Analyze > Inspect Code. The results of the inspection appear in the Inspection Results window. see details here: https://developer.android.com/studio/write/lint#manuallyRunInspections

Omar
  • 71
  • 4
0

The message suggests to recompile with -Xlint flag in command-line, to get more issue details, but even if you do, the next log may ask for --stacktrace flag.

In build.gradle file, do something like:

import org.gradle.api.logging.configuration.ShowStacktrace
allprojects {
    // Same as passing --stacktrace option.
    gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS

    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
}

Note that the import may not be required (just imported to be clear).

Also as y4n9b0 said; Then you can use warnings' details to fix issues.
For example, you can replace deprecated method with new method (I mean, there must be a new-method, since old-method has been deprecated).

But sometimes for backward compatibility, we don't want change our code, and just want to get rid of compile-time warnings; simply add in front of the deprecated method:

@SuppressWarnings("deprecation")
Top-Master
  • 7,611
  • 5
  • 39
  • 71