How to add java compiler options when compiling with Android Gradle Plugin?

后端 未结 3 693
无人共我
无人共我 2020-12-16 11:58

I have a build.gradle file with dependencies { classpath \'com.android.tools.build:gradle:0.13.3\'} and apply plugin: \'com.android.applicati

3条回答
  •  心在旅途
    2020-12-16 12:38

    I tried the solution posed by @Konrad Jamrozik but it didn't work with my project due to flavours in my project.

    Given that we're just turning on additional warnings, not something that's significantly changing how the compiler operates, I don't see it being an issue that it will be added to both release and debug builds. As such, this answer has a cleaner method that works with flavours: How to add -Xlint:unchecked to my Android Gradle based project?

    In my case, adding this to the build.gradle file of the affected module:

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

提交回复
热议问题