如何在 Android 项目上设置自定义 Java 编译器参数? [英] How to set custom Java compiler args on an Android project?

查看:34
本文介绍了如何在 Android 项目上设置自定义 Java 编译器参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将以下内容放在我的项目 gradle 文件的末尾:

I'm putting the following at the end of my project gradle file:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs += 
            ['-Xep:MissingOverride:ERROR', 
             '-Xep:MissingCasesInEnumSwitch:ERROR',]
    }
}

但是,在我的代码中,如果我在某处删除 @Override 注释或删除 switch 语句,我的 Android 项目仍然会构建.它不应该因错误而失败吗?

However, in my code if I remove an @Override annotation somewhere or remove a switch statement, my Android project still builds. Shouldn't it fail with an error?

推荐答案

我在 google 上搜索了你的问题,发现了这个 post描述了您的问题,解决方案如下所示:

I googled your problem and found this post that described your problem and the solution looks like this:

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

看起来,android 项目的 gradle 构建与 java 项目的不同,并且您无法访问任务 CompileJava 本身,如我在第一条评论中所述.

As is seems the gradle build is different for android projects than for java projects and you can't access the task CompileJava itself as stated in my first comment.

这篇关于如何在 Android 项目上设置自定义 Java 编译器参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆