Custom lint rules are not picked up consistently

959 views
Skip to first unread message

Balachandar KM

unread,
Jul 22, 2019, 1:39:23 PM7/22/19
to lint-dev
Hi,
We have a java module with 10+ custom lint rules. This module is added to our android-app module and android-library module using “lintChecks”. Recently we started to notice that the custom lint rules don’t run regularly in the android-app module alone (Works consistently in the android-library module).  When we run `./gradlew :app:lint<Flavor>Debug` it runs our custom lint rules randomly. Sometimes, It passes and fails in back to back runs without any code change!!

I have checked the lint.jar generated by `./gradlew :app:prepareLintJar` and it does contain all our custom lint rules. I am not sure what else to check to debug this issue further. Any help is greatly appreciated. Thanks in advance.

Android Gradle Plugin Version: 3.4.1 (Also tried 3.4.2 and it didn’t work as well)
Lint Version : 3.4.1

Thanks,
Bala

Steven Schoen

unread,
Jul 22, 2019, 2:28:16 PM7/22/19
to lint-dev
Since you're on AGP 3.4, the library should be using lintPublish, not lintChecks.

Jake Wharton

unread,
Jul 22, 2019, 2:31:07 PM7/22/19
to Steven Schoen, lint-dev
lintPublish is for embedding the lint rules into the aar for consumers of your library in that format. If you're just running custom lint checks from a module on your own modules, lintChecks is the appropriate configuration.

--
You received this message because you are subscribed to the Google Groups "lint-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lint-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lint-dev/53291d01-5845-485a-ba7a-1b033942b095%40googlegroups.com.

Steven Schoen

unread,
Jul 22, 2019, 2:35:56 PM7/22/19
to lint-dev
Oops, you're right, I was thinking the lint checks were for testing things in those libraries.


On Monday, July 22, 2019 at 10:39:23 AM UTC-7, Balachandar KM wrote:

Brandon

unread,
Jul 22, 2019, 3:36:27 PM7/22/19
to lint-dev
Being that you're on AGP 3.4+, this SHOULDN'T be the case, but have you checked your gradle HOME cache for instances of the lint.jars that may cause failing due to double reports (issues being reported both from those lint.jars and the one created by prepareLintJar)? 

You can see if they are being cached by doing `find ~/.gradle -name lint.jar`. If they exist, they will be causing the failures you see. You can then run the same command appended with `-delete` and it will get rid of them. A key way of identifying that this is happening is matching the issues you are seeing thrown with your baseline. If the issue is already baselined but the build fails on it, it is an instance of double reporting. Our team is currently facing this, but we are on AGP < 3.4. Just wondering if this is a bug, because the behavior sounds very similar to what we face (inconsistent failures).

Let me know what you find!

Balachandar KM

unread,
Jul 23, 2019, 11:08:23 AM7/23/19
to lint-dev
Thanks for your response Brandon. After clearing the lint jars, lint task started work again consistently in my local machine :) But it still exhibits the same behaviour in CI even after clearing the lint jars just before running the lint task! Are there more places where these lint jars can be cached other than ./gradle directory?

Thanks

Balachandar KM

unread,
Jul 23, 2019, 12:19:19 PM7/23/19
to lint-dev
Just to add on my previous reply, All the default android lint rules are working fine in CI. Only custom lint rules exhibit this inconsistent behaviour.

Brandon

unread,
Jul 23, 2019, 12:24:00 PM7/23/19
to lint-dev
In my experience, no. And we actually have the same issue on CI, it's inconsistent but the failures are still definitely caused by being in the gradle cache. We haven't found an answer for that yet, but I am disappointed that it sounds like the issue still happens on 3.4 even though I though the lintChecks and lintPublish changes aimed at fixing that.

Brandon

unread,
Jul 23, 2019, 1:45:37 PM7/23/19
to lint-dev
Yeah, it will only be your custom rules because these are being (incorrectly) packaged with the library via lintChecks('your-custom-rules'). Is it possible that your library is binaried and has not been re-generated since the uptick to 3.4 so that the lint rules aren't bundled in the aap? If that's not the case then it very well may be an issue in the gradle configuration (out of your hands). Would love for Tor or Matthew to jump in here :D

Balachandar KM

unread,
Jul 25, 2019, 5:43:11 AM7/25/19
to lint-dev
Hmmm.. I am not sure what is going wrong under the hood. It would be great if there is a way to list all the available rules for the lint gradle task.

I tried `--refresh-dependencies` and `--no-build-cache`. Both of them resulted in no change at all.

Is there any gradle param like `-Pandroid.lint.debug=true` (I made this up for an example) which logs more useful information? At the moment, it works for some collegues and does not work at all for some collegues and in CI. So hard to figure out.

Thanks

Matthew Dolan

unread,
Oct 28, 2019, 4:21:39 PM10/28/19
to lint-dev
Having taken another look at the issues we've been having we've found a bug in lint, raised in issue https://issuetracker.google.com/issues/143455360 where if one of the early on lint.jar files being added defines the lint registry using the service loader syntax (as our project does through use of autodispose) then any later rules will not be added as the function exits early.
Reply all
Reply to author
Forward
0 new messages