Mar*_*ark 6 java android compiler-warnings android-gradle-plugin
我使用com.android.application插件在gradle中设置了一个Android项目.我希望javac lint警告触发错误而不仅仅是警告.
以下工作适用于警告:
tasks.withType(JavaCompile).all {
options.compilerArgs.add("-Xlint:all")
}
Run Code Online (Sandbox Code Playgroud)
但是,添加-Werror:
tasks.withType(JavaCompile).all {
options.compilerArgs.add("-Xlint:all")
options.compilerArgs.add("-Werror")
}
Run Code Online (Sandbox Code Playgroud)
导致构建完全失败(不是以正确的方式):
FAILURE:构建因异常而失败.
*出了什么问题:任务执行失败':app:compileDebugJava'.
显示java.lang.NullPointerException
*尝试:使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行以获取更多日志输出.
建筑失败
使用--stacktrace调用gradle显示:
*异常是:org.gradle.api.tasks.TaskExecutionException:任务':app:compileDebugJava'的执行失败.在org.gradle上的org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)位于org.gradle.api.internal的org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)上的.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) .tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:
是否添加-Werror不受支持?
javac lint
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-Werror"
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果将是下一个
....
:app:compileDebugJava
D:\Android\stack-overflow\ui\app\src\main\java\com\tivogi\ui\activity\MainActivity.java:22: warning: [deprecation] getLastNonConfigurationInstance() in Activity has been deprecated
getLastNonConfigurationInstance();
^
error: warnings found and -Werror specified
1 error
1 warning
:app:compileDebugJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.421 secs
Run Code Online (Sandbox Code Playgroud)
Android Lint
来自Gradle Plugin用户指南的Android Lint支持
android {
lintOptions {
...
// if true, treat all warnings as errors
warningsAsErrors true
...
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4080 次 |
最近记录: |