且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在“构建”中检测到哪些错误在Android Studio中 - Gradle的角色

更新时间:2023-10-17 11:23:46

Why does Gradle Build only detect some errors, but other have to be found via lint?

Lint errors are not compile errors, but code issues, and by default AndroidStudio will not check those. (Same goes for standard javac).

What categories of errors will be found via Gradle Build?

Gradle will detect all compile time errors, annotation processing, packaging errors, dex, signing, incorectly defined xml, incorrect file naming, etc.

How hard is it to add something to the Gradle Build script to find all errors?

Surprisingly easy in fact, source

To enable lint checks when compiling add in your application level build.gradle

android {
   lintOptions {
       // set to true to turn off analysis progress reporting by lint
       quiet false
       // if true, stop the gradle build if errors are found
       abortOnError true
       // if true, only report errors
       ignoreWarnings false
       }
   ...
}

If this will not work for U, add lint after each make, to do this you can follow this answer

I will add that this config will detect all enabled inspections with severity warning and error under:

File > Other Settings > Default Settings > Editor > Inspections 

Android Studio will run code inspections checks live so all lint warnigns / errors are displayed in code while editing, lint errors are marked with red underscore, and warnings by marking code fragment with yellow background. Even if lint errors are marked the same as compile time errors they will not stop build by default.