25

How do I run Android Lint so it only reports on my project module, and ignores any library projects I'm using? Even when I aim Lint at my project's module, it spews out lists of issues in the library projects which I'm not interested in - I want to focus effort on fixing issues in my own code.

I can't see a parameter to specify whether it follows references to library projects or not, but maybe you can see how to do it.

Gustavo Pagani
  • 6,583
  • 5
  • 40
  • 71
Ollie C
  • 28,313
  • 34
  • 134
  • 217

4 Answers4

17

The Android SDK Tools 21.1 introduced a new, convenient feature to solve this problem / bug.

Have a look at the Android Lint overflow menu and you will find the option Skip Library Project Dependencies which will do exactly what you are looking for.

enter image description here

jenzz
  • 7,239
  • 6
  • 49
  • 69
  • What about general warnings I have for Java ? Is it possible to make it ignore all of the warnings and errors on library projects ? – android developer Apr 14 '13 at 14:30
  • 2
    This fixes the problem. It should be voted as the correct solution. The accepted answer produces the problem reported by @frank – Imanol Apr 17 '13 at 09:36
  • 2
    This works for Eclipse, but how do I get the similar behavior running in command line? I'm running lint from command line as part of the build process (it breaks the build if unused resources are committed). Right now, it will break if using any library project. – tdevaux Jun 26 '13 at 17:39
  • 1
    I tried this and it worked as long as I didn't build the app. When I choose to build the app with "Export Signed Application Package.." all the lint errors for the languages are back. And if I set lint translation errors to warning and build, Google Play thinks my app include all the languages for the libraries as well - which is basically all of them. – flogvit Jul 01 '13 at 16:04
  • This doesn't solve the problem, since sometimes we create our own libraries, and they should be checked, as opposed to third party libraries that we'd like to ignore... – android developer Apr 16 '14 at 21:23
6

If you are using Eclipse, go to the library project's properties (right click on project -> Properties) and under "Android Lint Preferences" click "Ignore All" and than OK.

muscardinus
  • 679
  • 1
  • 6
  • 11
  • 1
    Nevertheless this is a working solution. The preferences changed in Eclipse are stored in a lint.xml file inside the project, which afterwards is also evaluated when running lint from the command line. – Bananeweizen Jul 07 '12 at 11:19
  • Interesting to know, but no help to me as I don't use Eclipse, I use IntelliJ. – Ollie C Jul 16 '12 at 10:33
  • 7
    I just tried this solutin, and it does not work. When running Lint on the Library, Lint does not report any issues. But when then when I run Lint on my project the issues from the Library project are still reported. – Frank Harper Aug 05 '12 at 15:42
  • on the command line, did you make sure to pass the name of the confix file to the lint command? – lowellk Aug 17 '12 at 23:42
  • @FrankHarper: There is now a new option in the latest ADT tools which fixes that bug. Have a look at my answer. – jenzz Feb 24 '13 at 01:17
  • @OllieC For linting from command line see my answer: http://stackoverflow.com/a/24845800/1795426 – user11153 Jul 20 '14 at 10:10
2

My solution was to modify the lint output to filter the other projects errors and warnings.

I did this with a custom ant task and xslt file to filter.

Assuming you are using ant to do your android builds you modify the custom_rules.xml:

<property name="lint.script" value="${sdk.dir}/tools/lint"/>
<property name="lint.report" location="${basedir}/lint-results-all.xml"/>  
<property name="lint.project.loc" location="${basedir}"/>

<target name="lint">
<!-- lint --xml lint-results-all.xml -->
  <exec executable="${lint.script}">
   <arg value="--xml"/>
   <arg value="${lint.report}"/>
   <arg value="${lint.project.loc}"/>
  </exec>
</target>

<target name="runlint" depends="lint">
    <xslt in="lint-results-all.xml" out="lint-results.xml" style="lint-cleanup.xslt" />
</target>

Then I added a XSLT file that strips the issues for the other projects: lint-cleanup.xslt.

The XSLT file basicallly checks if the file location does NOT contain "sherlock" then copy to a new output file. You can modify to suit your needs. It may also works as start-with instead of contains.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="issue">
            <xsl:variable name="location_to_filter" select="'sherlock'" />
            <xsl:if test="not(contains(location/@file, $location_to_filter))">
                    <xsl:copy-of select="."/>
            </xsl:if>
    </xsl:template>

<xsl:template match="@*|node()">
  <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy>
</xsl:template>

</xsl:stylesheet>

To run the lint report I simply added it to the command line in my ant build on Jenkins.

ant clean debug runlint

You should get lint-results-all.xml and a lint-results.xml (with the filtered content). I use this with the Jenkins Android Lint plugin

The ugly part about this solution is that it still runs lint on the other project, so you waste a few cpus cycles. Also the name that you are filtering is in the xslt file, so it may not scale well if you use multiple 3rd party libraries you need to filter. However, XSLT is powerful enough it should be able to easily create a better filter as needed.

sww314
  • 1,252
  • 13
  • 17
2

Use lint.xml for a more general approach, which also works outside of Eclipse. Just put the used libraries (e.g. Action Bar Sherlock and Facebook) to ignore:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="all">
        <ignore regexp="target/classes/com/actionbarsherlock/.*" />
        <ignore regexp="target/classes/com/facebook/.*" />
    </issue>
</lint>

This approach also works with CI solutions like Jenkins.

Markus Junginger
  • 6,950
  • 31
  • 52