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

后端 未结 3 687
无人共我
无人共我 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:41

    I found the following solution based on Gradle Plugin User Guide on Manipulating Tasks and Gradle DSL doc about JavaCompile:

    Add to build.gradle:

    preBuild {
        doFirst {
            JavaCompile jc = android.applicationVariants.find { it.name == 'debug' }.javaCompile
            jc.options.compilerArgs = ["-Xlint:unchecked"]
        }
    }
    

    The application variants are null during Gradle's configuration phase and the required JavaCompile task also doesn't exist, thus I do the modification in the execution phase instead.

提交回复
热议问题