2012-03-26

Comprendre un plantage (simple) de lint

Je n'ai pas eu l'occasion de faire un billet à ce sujet, mais le très récent ADT 17 apporte  une nouvelle version de lint dopée au stéroïdes.

Malheureusement, il peut arriver que (comme sur l'image de l'article) lint se casse les dents sur votre projet en cours. C'est assez ennuyeux que l'outil d'aide à la découverte de potentiel bug se banane, mais on va voir que ce n'est pas TOUT lint qui est concerné.

Lint en CLI

L'outil lint est accessible en ligne de commande et est assez simple d'emploi : il suffit de donner en paramètre le dossier du projet.
k@mbp /opt/android-sdk-update-manager/tools $ ./lint ~/workspace/JArriveDeSuite/

Scanning JArriveDeSuite: ................................................................................................................................................................Exception in thread "main" java.lang.NullPointerException
 at com.android.tools.lint.checks.IconDetector.checkDipSizes(IconDetector.java:651)
 at com.android.tools.lint.checks.IconDetector.checkResourceFolder(IconDetector.java:321)
 at com.android.tools.lint.checks.IconDetector.afterCheckProject(IconDetector.java:277)
 at com.android.tools.lint.client.api.LintDriver.checkProject(LintDriver.java:692)
 at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:285)
 at com.android.tools.lint.Main.run(Main.java:485)
 at com.android.tools.lint.Main.main(Main.java:131)
Nous voila bien plus avancé qu'avec le message d'Eclipse.

./lint --help

Regardons ce que nous indique l'aide : --list et --disable semblent intéressants.
k@mbp /opt/android-sdk-update-manager/tools $ lint
k@mbp /opt/android-sdk-update-manager/tools $ ./lint 
Usage: lint [flags] <project directories>

Flags:

--help                   This message.
--help <topic>           Help on the given topic, such as "suppress".
--list                   List the available issue id's and exit.
--version                Output version information and exit.
--exitcode               Set the exit code to 1 if errors are found.
--show                   List available issues along with full explanations.
--show <ids>             Show full explanations for the given list of issue
                         id's.

Enabled Checks:
--disable <list>         Disable the list of categories or specific issue
                         id's. The list should be a comma-separated list of
                         issue id's or categories.
--enable <list>          Enable the specific list of issues. This checks all
                         the default issues plus the specifically enabled
                         issues. The list should be a comma-separated list of
                         issue id's or categories.
--check <list>           Only check the specific list of issues. This will
                         disable everything and re-enable the given list of
                         issues. The list should be a comma-separated list of
                         issue id's or categories.
-w, --nowarn             Only check for errors (ignore warnings)
-Wall                    Check all warnings, including those off by default
-Werror                  Treat all warnings as errors
--config <filename>      Use the given configuration file to determine whether
                         issues are enabled or disabled. If a project contains
                         a lint.xml file, then this config file will be used
                         as a fallback.

Output Options:
--quiet                  Don't show progress.
--fullpath               Use full paths in the error output.
--showall                Do not truncate long messages, lists of alternate
                         locations, etc.
--nolines                Do not include the source file lines with errors in
                         the output. By default, the error output includes
                         snippets of source code on the line containing the
                         error, but this flag turns it off.
--html <filename>        Create an HTML report instead. If the filename is a
                         directory (or a new filename without an extension),
                         lint will create a separate report for each scanned
                         project.
--url filepath=url       Add links to HTML report, replacing local path
                         prefixes with url prefix. The mapping can be a
                         comma-separated list of path prefixes to
                         corresponding URL prefixes, such as
                         C:\temp\Proj1=http://buildserver/sources/temp/Proj1. 
                         To turn off linking to files, use --url none
--simplehtml <filename>  Create a simple HTML report
--xml <filename>         Create an XML report instead.

Exit Status:
0                        Success.
1                        Lint errors detected.
2                        Lint usage.
3                        Cannot clobber existing file.
4                        Lint help.
5                        Invalid command-line argument.

Voyons ce qu'il y'a d'intéressant dans la liste --list
k@mbp /opt/android-sdk-update-manager/tools $ ./lint --list | grep icon
"IconDensities": Ensures that icons provide custom versions for all supported
"IconDipSize": Ensures that icons across densities provide roughly the same
"IconExpectedSize": Ensures that launcher icons, notification icons etc have
"IconDuplicates": Finds duplicated icons under different names
"IconDuplicatesConfig": Finds icons that have identical bitmaps across various
"IconNoDpi": Finds icons that appear in both a -nodpi folder and a dpi folder

L'erreur de la stacktrace de lint mentionnait "checkDipSizes", nous avons une option "IconDipSize". Je vais donc soumettre à nouveau mon projet à lint mais avec le parametre --disable IconDipSize
k@mbp /opt/android-sdk-update-manager/tools $ ./lint --disable IconDipSize ~/workspace/JArriveDeSuite/

Scanning JArriveDeSuite: ................................................................................................................................................................
Scanning JArriveDeSuite (Phase 2): ......
res/layout/wizard.xml:42: Warning: Duplicate id @+id/tvContactNum, defined or included multiple times in layout/wizard.xml: [layout/wizard.xml => layout/wizardfreq.xml defines @+id/tvContactNum, layout/wizard.xml => layout/wizardcontact.xml defines @+id/tvContactNum] [DuplicateIncludedIds]
            <include
            ^
    res/layout/wizardfreq.xml:11: Defined here, included via layout/wizard.xml => layout/wizardfreq.xml defines @+id/tvContactNum
    res/layout/wizardcontact.xml:35: Defined here, included via layout/wizard.xml => layout/wizardcontact.xml defines @+id/tvContactNum
res/layout/wizard.xml:113: Warning: android:enabled is deprecated: Use state_enabled instead [Deprecated]
            android:enabled="false"
            ^
res/drawable-hdpi: Warning: Missing the following drawables in drawable-hdpi: ._iconjarrive.png (found in drawable-mdpi, drawable-xhdpi) [IconDensities]
res/drawable-xhdpi: Warning: Missing the following drawables in drawable-xhdpi: ic_launcher.png (found in drawable-hdpi, drawable-mdpi) [IconDensities]
res/layout/wizardfreqinterval.xml:36: Warning: [I18N] Hardcoded string "Vous arrivez dans :", should use @string resource [HardcodedText]
                    android:text="Vous arrivez dans :"
                    ^
res/layout/wizardfreqinterval.xml:106: Warning: [I18N] Hardcoded string "Toutes les :", should use @string resource [HardcodedText]
                    android:text="Toutes les :"
                    ^
0 errors, 6 warnings

Conclusion

L'outil lint est déjà excellent et pertinent, mais pas exempt de petits soucis. L'intégration dans Eclipse est un peu laconique mais je suis confiant sur le devenir de cet outil.
Si ça vous interesse, le problème de mon projet était en relation avec ces icônes xhdpi manquantes.
Enregistrer un commentaire