Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What errors get detected in "build" in Android Studio - role of Gradle

I'm transitioning over from Eclipse to Android Studio and I find that I'm still confused about the different components of Android Studio regarding detecting errors. I have a project with about 20 Java files and 30 XML files. I recently ran a clean and build and got

Gradle build finished with 5 error(s) in 13s 397 ms

Two XML files were indicated and in both of them there was whitespace in front of the first element with an error saying ...

Xml declaration should precede all document content

So I fixed those and ran the build again with no errors.

I then ran Lint and found 8 more XML files with errors (NB, errors, not warning) saying "Element selector doesn't have required attribute:layout_height ". This error was apparently due to these files being in a layout folder instead of a drawable folder, although why that didn't cause problems in Eclipse is unclear.

My Questions:

  1. Why does Gradle Build only detect some errors, but other have to be found via lint?
  2. What categories of errors will be found via Gradle Build?
  3. How hard is it to add something to the Gradle Build script to find all errors?

Edit: actually this is also true for regular Java files - I'll get "0 errors" in the Gradle build and then I'll step into a source file in the debugger and see 4 errors from Lint.

like image 246
user316117 Avatar asked Nov 28 '16 21:11

user316117


1 Answers

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.

like image 115
Inverce Avatar answered Oct 16 '22 05:10

Inverce