Run Lint from console for only selected files

12,503

There is also a dedicated Lint CLI available which allows to check particular directories/files [1].

Examples:

lint theDirYouWantToCheck/
lint orOneParticularFile.xml

With the --check option you are also free to limit the checks which are performed. See lint --help for more information.

One remark: If you are facing something like...

main: Error: "main" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew :lint" instead. [LintError]

...just cd deeper into the directory structure.

  1. http://developer.android.com/tools/help/lint.html
Share:
12,503

Related videos on Youtube

jmm
Author by

jmm

Web and mobile developer. Also, been a tester in the past.

Updated on June 30, 2022

Comments

  • jmm
    jmm almost 2 years

    I am trying to create a custom Git pre-commit hook that checks (using Lint from console, via "gradlew") for possible issues. However, I can't find how to run Lint only in provided files. If I run something like

    ./gradlew app:lint
    

    Lint analyzes all the project files, and this operation can take quite a bit of time. In this document, there is a "Incremental Lint" section, which covers something similar to what I am looking for. I also found this open issue, that is quite the same as my problem, but seems to be more specific, since it "automatically" retrieves the files to be linted.

    To sum up: is it possible to run Lint from command line over a collection of files? Or I am just stucked in running it for the whole project?

    Best regards

  • jmm
    jmm about 9 years
    This is quite useful. Thanks! Just a small comment: if lint isn't in the path, it should by placed in %ANDROID_HOME%\sdk\tools
  • mallaudin
    mallaudin almost 8 years
    Doesn't work. Where should I go deeper when I am layout resource directory?
  • rana_sadam
    rana_sadam almost 7 years
    Agree with @mallaudin it didn't work on my side either
  • André Diermann
    André Diermann almost 7 years
    What does not work exactly? Do you get an error message?
  • Abubakar
    Abubakar over 6 years
    when I run it on some file xyz.java, it says task 'xyz.java' not found in project root directory.
  • channae
    channae over 6 years
    I get following error when i'm using CLI, myapp: Error: "myapp" is a Gradle project. To correctly analyze Gradle project s, you should run "gradlew :lint" instead. [LintError]
  • Kaskasi
    Kaskasi about 6 years
    What @a11n is trying to say is: when running /path/to/lint /app/src/main/java/SomeFile.java gives you the is a Gradle project error then cd /app/src/main and run lint from here with /path/to/lint /java/SomeFile.java
  • NullByte08
    NullByte08 about 4 years
    So I ran the command after getting into the directory in which i want to perform lint like this ...\app\src\main\res>lint layout But it still gives me that error. main: Error: "main" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew :lint" instead. [LintError] 1 errors, 0 warnings
  • EmMper
    EmMper over 3 years
    @Kaskasi I tried what you said and it still showed me the same error.