How to add -Xlint:unchecked to my Android Gradle based project?

前端 未结 7 881
囚心锁ツ
囚心锁ツ 2020-11-29 16:05

I tried to add the following to the root build.gradle file:

subprojects {
    gradle.projectsEvaluated {
        tasks.withType(Compile) {
              


        
相关标签:
7条回答
  • 2020-11-29 16:31

    I'm not sure the problem was about using the Gradle subprojects configuration parameter, but the syntax you used:

    options.compilerArgs << "-Xlint:unchecked -Xlint:deprecation"
    

    This worked for me:

    subprojects {
      gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
          options.compilerArgs += [
            '-Xlint:unchecked', // Shows information about unchecked or unsafe operations.
            '-Xlint:deprecation', // Shows information about deprecated members.
          ]
        }
      }
    }
    

    or

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

    If you only want to add one option (you would normally add more), inside the task JavaCompile you just need to add:

    options.compilerArgs << "-Xlint:unchecked"
    

    You can find more information about Lint here and here.

    0 讨论(0)
提交回复
热议问题