如何使用-Xlint重新编译:弃用

And*_*eas 33 android lint gradle

我不使用Android Studio,但我使用命令行构建所有内容build.gradle.我生成一个像这样的Lint报告:

./gradlew lint
Run Code Online (Sandbox Code Playgroud)

这正确地生成了一个Lint报告,但它也说明了这一点:

Note: MyActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Run Code Online (Sandbox Code Playgroud)

这让我想知道我怎么能这样做?我尝试过以下方法:

./gradlew lint -Xlint:deprecation
Run Code Online (Sandbox Code Playgroud)

但它不起作用.它说:

Problem configuring task :app:lint from command line.
Unknown command-line option '-X'.
Run Code Online (Sandbox Code Playgroud)

那我怎么-Xlint:deprecation能通过gradle 传递到Lint?

And*_*eas 57

要回答我自己的问题,添加这个build.gradle就可以了:

allprojects {
    ...

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:deprecation"
        }
    }   
}
Run Code Online (Sandbox Code Playgroud)

  • 这必须进入项目级“build.gradle”文件。 (4认同)
  • 哪个`build.gradle`? (3认同)