Android Lint report for my project only, excluding library projects?

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


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.


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.