我的build.gradle
文件包含dependencies { classpath 'com.android.tools.build:gradle:0.13.3'}
和apply plugin: 'com.android.application'
。
当我进行调试构建时,我得到:
gradle clean assembleDebug
:myapp:preBuild
(...)
:myapp:compileDebugJava
Note: C:\path\to\MyClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:myapp:preDexDebug
(...)
:myapp:assembleDebug
BUILD SUCCESSFUL
如何将-Xlint:unchecked
添加到基础任务? Gradle Plugin User Guide on Java compilation options没有任何帮助。
答案 0 :(得分:24)
我尝试了@Konrad Jamrozik提出的解决方案,但由于项目中的风味,它无法用于我的项目。
鉴于我们只是打开其他警告,而不是显着改变编译器运行方式的东西,我认为它不会被添加到发布和调试版本中。因此,这个答案有一个更清晰的方法,适用于口味:How to add -Xlint:unchecked to my Android Gradle based project?
就我而言,将其添加到受影响模块的build.gradle文件中:
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
答案 1 :(得分:5)
我找到了基于Gradle Plugin User Guide on Manipulating Tasks和Gradle DSL doc about JavaCompile的以下解决方案:
添加到build.gradle
:
preBuild {
doFirst {
JavaCompile jc = android.applicationVariants.find { it.name == 'debug' }.javaCompile
jc.options.compilerArgs = ["-Xlint:unchecked"]
}
}
在Gradle的配置阶段,应用程序变体为null
,并且所需的JavaCompile
任务也不存在,因此我在执行阶段进行修改。
答案 2 :(得分:0)
将此添加到 build.gradle 文件中:
android { // <---
tasks.withType(JavaCompile) {
configure(options) {
options.encoding = 'UTF-8'
options.debug = true
options.failOnError = true
options.warnings = true
options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked'
}
}