List of lint checks that are only run in AS?

1,085 views
Skip to first unread message

Kiran Rao

unread,
Apr 26, 2017, 9:50:41 AM4/26/17
to lint-dev
Hi,

I'm not sure if this question belongs here or in adt-dev, but I'd like to know if there is a list of lint checks that are _only_ run in Android Studio, but not when running lint command line (and vice-versa)?

Motivation:
We have our CI run lint and fail the build if there is a lint error. However since some lint checks (like nullability) are not run on CI, I would like to know in advance since then we can pay extra attention during code review.

Tor Norbye

unread,
Apr 27, 2017, 11:29:03 PM4/27/17
to lint-dev
When you invoke Analyze > Inspect Code... in the IDE, you're not just running Android Lint, you're running IntelliJ's full set of inspections. (In the Android plugin we hook lint up to their inspection machinery such that they mostly act as if they're themselves IDE inspections.)
There are around 300 Android lint checks -- but there is an even larger number of IDE inspections.
Generally, in lint we try to keep the checks mostly Android specific -- there's no need to go there and warn about things (such as dead code) when the IDE will also warn about it -- you'd get a double set of highlights.

Therefore, when you run lint from the command line, you're only getting the lint checks, not the IDE inspections. 
This, by the way, is why Android Lint checks are organized into a separate set of categories in the inspections UI:

















We *could* place the various lint checks into their individual categories instead (security, performance, accessibility, etc) and blend them in with the other IDE inspections, but it seemed important to understand what's lint, and what's not.

It is possible to run the IntelliJ inspections from the command line too -- look at the inspect.sh script that ships with the IDE in the bin/ folder. However, if you use it you'll need to check in the IDE project files (.idea, *.iml etc) since that script won't load Gradle projects and attempt to do a Gradle sync to infer the model from the build.gradle files -- and the output isn't very user friendly - you get a folder full of .xml files, one per inspection. But it's pretty easy to transform it with XSLT, and if you use JetBrains' TeamCity server product I believe they have good ways of visualizing these things. (You can also expose these files as build artifacts; users can download these files and load them into the inspections UI as Offline results.)

Finally that leaves the discrepancy between Lint running inside the IDE and in Gradle. There *are* some differences, but there are fewer and fewer of them. Until 2.3 a lot of checks had separate implementations in the IDE and in lint, but that's no longer the case.
The difference is really that the bytecode based checks (ClassScanner implementations) don't run in the IDE. That's because we often don't have up to date .class files when the inspections run (and it wasn't trivial to hook up building to the inspections process.) But bytecode based checks have many, many disadvantages over AST based checks - so I've been porting nearly all of the previous class scanners to AST scanners. There's only a couple of them left, and I wouldn't worry about them -- the important checks are all running in both places.

(There are a couple of other discrepancies too; when lint runs in the IDE it gets access to services from the IDE, such as the ability to read its proxy settings; useful if you enable the off-by-default gradle check which checks whether all the artifacts are the latest available versions by connecting to maven central's search, and the ability to look up recent SDK repository versions cached by the SDK manager in the IDE etc.)

-- Tor

Kiran Rao

unread,
Apr 28, 2017, 3:38:44 AM4/28/17
to lint-dev
Thanks for the detailed explanation Tor!

I guess I got confused because I saw a lint check triggered by an Android support library annotation (@Nullable, @NonNull) not work from the lint command line. So I thought there might be more such checks.

But now that I think of it, this case is an exception in that IntelliJ already had nullness-checks built-in and also had the ability to configure what annotations to recognize for nullness checking. So AS just re-used that feature.

Is that right?

On Friday, 28 April 2017 05:29:03 UTC+2, Tor Norbye wrote:

Tor Norbye

unread,
Apr 28, 2017, 12:33:42 PM4/28/17
to Kiran Rao, lint-dev
Yes.

--
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 post to this group, send email to lint...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lint-dev/22450b57-1b36-479a-be19-1d803dd3ad70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ekrem şahin

unread,
Jan 11, 2019, 4:46:36 AM1/11/19
to lint-dev
Hi ,

I have one issue and can not find a way to fix it.
I am trying to run ./gradlew lint for my android app and it is only finding warnings/errors on xml files and does not look for error/warnings for java files.
When I try to inspect code from Android Studio it finds every error/warnings.
How I can run ./gradlew lint command in order to run it for including the java files as well ?

Regards

28 Nisan 2017 Cuma 19:33:42 UTC+3 tarihinde Tor Norbye yazdı:

Tor Norbye

unread,
Jan 11, 2019, 11:06:23 AM1/11/19
to lint-dev
On Friday, January 11, 2019 at 1:46:36 AM UTC-8, ekrem şahin wrote:
Hi ,

I have one issue and can not find a way to fix it.
I am trying to run ./gradlew lint for my android app and it is only finding warnings/errors on xml files and does not look for error/warnings for java files.
When I try to inspect code from Android Studio it finds every error/warnings.
How I can run ./gradlew lint command in order to run it for including the java files as well ?

That's surprising; ./gradlew lint *should* include all the java files. Is there something unusual about how your source sets are configured from build.gradle? Any details on how to reproduce this?

-- Tor 

ekrem şahin

unread,
Jan 14, 2019, 2:43:35 AM1/14/19
to lint-dev
Hi Tor,

I have made some investigation and it seems to me source sets are fine.So I have added following to my build.gradle file:

lintOptions{
checkAllWarnings true
abortOnError false
}

Now I can see some warnings on java files too.Should we add this lintOptions to build.gradle ?
And I intentionally added an unused variable to one of my java classes to see if lint fires a warning for this but It does not raise a warning for this.
What is the reason for that Can you give me an idea , Should I add some enable '' flags to build.gradle file ?

Regards

11 Ocak 2019 Cuma 19:06:23 UTC+3 tarihinde Tor Norbye yazdı:

Tor Norbye

unread,
Jan 14, 2019, 10:17:02 AM1/14/19
to lint-dev
Aha, I think I know what's going on: you're looking for IntelliJ inspections to show up from the command line, right?
That's a common, and very reasonable, misunderstanding.

Basically, there are two separate "lint" engines running the IDE: IntelliJ's inspections machinery, and Android Lint. We've integrated Android Lint in the IDE such that it looks just like IntelliJ's own inspections.; runs on the fly, integrates with the inspections UI in the Options panel, uses the same quickfix shortcut actions, etc etc. However, IntelliJ inspections themselves are quite different from Android Lint checks internally, and in particular, they don't run as part of Android Lint when invoked outside of the IDE. There *is* a way to run IntelliJ inspections from the command line too, via the inspect.sh script that ships with the IDE, but it requires quite a bit of fiddling and the output reports is just a folder of XML reports.

-- Tor

Said Tahsin Dane

unread,
Jan 14, 2019, 6:13:30 PM1/14/19
to Tor Norbye, lint-dev
Tor, since the subject just came up, I want to share this issue I opened before https://issuetracker.google.com/issues/119314730

As you mentioned, Android Lint works similar to IntelliJ inspections in the IDE. But when any of the inspections run, Android Studio says Android Lint is running. It is just a small wording/copy issue.

Would it make sense to change the title when it is actually not Android Lint? I believe this contributes to the confusion. 

--
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 post to this group, send email to lint...@googlegroups.com.

ekrem şahin

unread,
Jan 15, 2019, 12:35:04 AM1/15/19
to lint-dev
Hi Tor,

So I need to use gradlew lint but I was thinking that lint static code analyzer also looks for unused variable etc as in the clang for android.
So still I want to use ./gradlew lint but If gradlew lint can not find such warnings than maybe I will only search for the err/warnings
what lint is checking with checkAllWarnings true paramater in lint options.

Regards

14 Ocak 2019 Pazartesi 18:17:02 UTC+3 tarihinde Tor Norbye yazdı:

Said Tahsin Dane

unread,
Jan 15, 2019, 3:03:43 AM1/15/19
to ekrem şahin, lint-dev
Hi Ekrem,

Here is the long list of all available lint checks with explanations

--
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 post to this group, send email to lint...@googlegroups.com.

ekrem şahin

unread,
Jan 15, 2019, 3:08:11 AM1/15/19
to lint-dev
Hi Said,

I have seen the list thank you , I am already using checkAllWarnings true options.So These all warnings should be checked I guess.
I am only surprised that this unused variable warning not belong to any lint warning type because I do not raised warning for unused variable case.

Regards

15 Ocak 2019 Salı 11:03:43 UTC+3 tarihinde Said Tahsin Dane yazdı:

Said Tahsin Dane

unread,
Jan 15, 2019, 3:23:23 AM1/15/19
to ekrem şahin, lint-dev
Android Lint is more for Android related things. They have unused resources check as an example. You can use SpotBugs, or Detekt for unused variable detection

Reply all
Reply to author
Forward
0 new messages