getting lint.xml to work with gradle

6,506 views
Skip to first unread message

Michael Barany

unread,
Jan 15, 2014, 3:31:01 AM1/15/14
to adt...@googlegroups.com
Anyone know what I'm doing wrong?


My project structure is pretty straight forward.
/build.gradle
/app/build.gradle
/app/lint.xml

lint options in /app/build.gradle:
    lintOptions {
        abortOnError false
        absolutePaths false
        lintConfig file("lint.xml")
    }

lint.xml file contents:
<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="MissingTranslation">
        <ignore path="res/values/qa-strings.xml" />
    </issue>
</lint>

I also tried the path src/main/res/values/qa-strings.xml

The Lint Report still tells me "MissingTranslation: Incomplete translation" in that file I'm trying to ignore.

thanks!

Dal

unread,
Jan 16, 2014, 4:54:33 AM1/16/14
to adt...@googlegroups.com
I had this same issue - try app/src/main/res/values/qa-strings.xml

Michael Barany

unread,
Jan 16, 2014, 4:12:31 PM1/16/14
to adt...@googlegroups.com
thanks! that worked.

Xavier Ducrohet

unread,
Jan 16, 2014, 5:05:54 PM1/16/14
to adt...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Dal

unread,
Jan 17, 2014, 6:48:23 AM1/17/14
to adt...@googlegroups.com
Hi Xavier,

On a related note, I would like our team of developers to all be warned of the same issues in Android Studio by checking the lint.xml into source control, along with specifying lintOptions in the build.gradle (rather than everyone having the same Inspection settings in Android Studio). Is this currently possible?


Thanks,

Dal 

Xavier Ducrohet

unread,
Jan 17, 2014, 11:49:38 AM1/17/14
to adt...@googlegroups.com
Studio should be reading that information, I think.

Tor Norbye

unread,
Jan 17, 2014, 12:02:16 PM1/17/14
to adt...@googlegroups.com
You currently can't. It should be relatively straightforward to let you suppress issues via lint.xml and lintOptions in build.gradle, and we should do that ASAP. I've filed issue
to track this.

It may not be possible to let you change severities (from warning to error or error to warning) and have those be respected in the IDE. (The reason for this is that lint is integration into Studio/IntelliJ by mapping each lint rule into a native IntelliJ "inspection". Each inspection has a severity which is specified statically in an XML file. It can be modified by the user in the Options dialog, but I think those apply globally; I'm not sure we have plugin access to modify them, and even if we did we wouldn't want to modify them globally, we'd want it to be on a per module basis (since that's where each lint.xml can set their own severity).

-- Tor

Tor Norbye

unread,
Jan 17, 2014, 4:31:54 PM1/17/14
to adt...@googlegroups.com
Good news -- I looked into this, and in IntelliJ the severity of an issue is only an attribute of editor annotations, and we do get hooks to customize those on a per creation basis, so I have fix pending for this -- it will now pick up your lint.xml configurations, including disabling issues, including changing severity and including ignoring certain paths.

(The issue with the ignore path needing to include app/ is also fixed; that was a separate bug which should be fixed in version 0.8 of the gradle plugin.)

-- Tor

Mike Kulasinski

unread,
Mar 13, 2014, 7:03:01 AM3/13/14
to adt...@googlegroups.com
Hey

Can you please confirm if Android studio does use the same lint configuration as gradle? When I run Inspect on Android Studio I have different errors than when I run it from command line by gradle. I have gradle 1.11 and Android Plugin 0.9

Also InvalidPackage error is only shout when I run the lint check from command line but not being shout when it is run from Android Studio.

We are aiming to have the same output of lint on developer machine as on our continuous integration server.

Thanks


Mike

Tor Norbye

unread,
Mar 14, 2014, 10:52:05 AM3/14/14
to adt...@googlegroups.com
On Thu, Mar 13, 2014 at 4:03 AM, Mike Kulasinski <mike.ku...@corp.badoo.com> wrote:
Hey

Can you please confirm if Android studio does use the same lint configuration as gradle? When I run Inspect on Android Studio I have different errors than when I run it from command line by gradle. I have gradle 1.11 and Android Plugin 0.9

Also InvalidPackage error is only shout when I run the lint check from command line but not being shout when it is run from Android Studio.

We are aiming to have the same output of lint on developer machine as on our continuous integration server.

I can confirm that they are *not* the same, though not deliberately so.

When lint is run inside IntelliJ and Android Studio, it does not run any of the bytecode-based lint checks (and the invalid package error is one of those).

They don't work for two reasons: 
(1) there may not be any bytecode yet, if the project has not been built (or the bytecode may be out of date w.r.t. the source files) since IntelliJ does not do compile-on-save; building is an explicit user action.
(2) lint's bytecode analysis uses ASM4, and it runs into class loading issues because of an incompatible version already used in IntelliJ

Both issues are fixable, and are on my radar.

-- Tor

Joe Hansche

unread,
May 5, 2014, 12:26:24 PM5/5/14
to adt...@googlegroups.com
Are there any other suggestions for this?  I am not able to get the <ignore path="res/values-*/strings.xml" /> feature to work at all.  I have about a dozen languages, but I only care about 2 of them to be "fatal" during the lintVitalRelease step.  The rest should be ignored (or maybe generate warnings when I run the "lint" step -- I just don't want them to be "fatal" during a release task).  I thought the <ignore/> feature was exactly what I was looking for, but it still doesn't work.

lint.xml:
<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="MissingTranslation">
        <ignore path="res/values-de/strings.xml" />
    </issue>
</lint>

This still fails to build due to MissingTranslation in the values-de file.  The only way I can get it to truly ignore the errors is by overriding the severity of the entire issue:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="MissingTranslation" severity="ignore" />
</lint>

That works, but then it won't catch the missing translations in the languages that I *do* want to be warned about.  Why does <ignore/> not work correctly then?

My project structure is set up using the old Eclipse/Ant style structure:

./ - root
./res/
./src/
  ... etc

My lint.xml file is in the project root.  I also tried using:  <ignore regex=".*/values-.*/.*\.xml" /> to no avail...

I want missing translations in the values-es/ directory to trigger the fatal MissingTranslation error, but I want to ignore all the other languages.  What needs to happen for this to work?

Both the CLI tool and the Gradle task are showing the same problem.

Tor Norbye

unread,
May 6, 2014, 1:38:23 PM5/6/14
to adt...@googlegroups.com
If you want to ignore all folders except for one or two you'll probably need to write a regexp which includes all but those folders. Make sure you're using the 0.10 version of the Gradle plugin, since the regexp version of <ignore> was added recently and probably wasn't available in the 0.9 and older versions.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Hansche

unread,
May 6, 2014, 2:02:36 PM5/6/14
to adt...@googlegroups.com
On Tue, May 6, 2014 at 1:38 PM, 'Tor Norbye' via adt-dev <adt...@googlegroups.com> wrote:
If you want to ignore all folders except for one or two you'll probably need to write a regexp which includes all but those folders. Make sure you're using the 0.10 version of the Gradle plugin, since the regexp version of <ignore> was added recently and probably wasn't available in the 0.9 and older versions.

The problem is even the @path version is not working as I was expecting.  However, if I use <ignore path="res/values/strings.xml"/> it *does* work, and ignores *all* MissingTranslation errors for all localized variants.  That is not what I wanted either.

So it seems that the reason this isn't working like I thought it would is because the actual lint error is occurring on res/values/strings.xml, with an error that *references* the other localized variant(s) of the resource.  So the error is stating "this is not translated in es, de, ... etc", but the source of the lint failure is in the default (english) version of the resource.  That's why ignoring the "-de" or "-es" versions has no impact at all, because the lint check is executing on the default resource, not the variant.

Is there any way to get Lint to handle this type of failure differently based on the variant it is comparing against?


Here is a simple use case to describe what I'm looking for:

res/values/strings.xml:
<string name="one">one</string>
<string name="two">two</string>
<string name="three">three</string>

res/values-de/strings.xml:
<string name="one">eins</string>
<string name="two">zwei</string>
 
res/values-es/strings.xml:
<string name="two">dos</string>
<string name="three">tres</string>

The MissingTranslation lint issue gets executed *only* on "res/values/string.xml" -- but for each resource found in that file, it also checks if there is a matching resources in _every_ res/values-*/strings.xml, and if not, raises an error.

I am looking for some way to indicate that I only want the "-es" version to be checked (for example), but I do not care about other variants.  So I would want an error that says "String resource 'one' is not translated in: es", but I *do not* want an error about "String resource 'three' is not translated in: de"

Perhaps a new tools attribute that I can add in res/values/strings.xml (e.g., similar to the default locale attribute <http://tools.android.com/tech-docs/tools-attributes#TOC-tools:locale>):

    <resources tools:requiredTranslations="es,fr">
        ...
    </resources>


That way any variant resources that I don't care about that just *happen* to have been translated is a bonus.. but if it's not translated, so be it (ignore);
but if there's a string resource that is missing in one of the languages I *do* care about, I want that to be a fatal lint error.


--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/xWSUOAq3RCM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Joe Hansche
Senior Applications Architect
100 Union Square Drive
New Hope, PA 18938
    

The public market leader in social discovery. (NYSE MKT: MEET)
Reply all
Reply to author
Forward
0 new messages