LoginSignup
37
33

More than 5 years have passed since last update.

Android:Lint

Last updated at Posted at 2014-12-26

from. Yukiの枝折 - Android:Lint

はじめに

Android LintはAndroidプロジェクトの潜在的不具合を検出するための支援プログラムである.
Android Lintでは次のようなAndroidに特化した問題を検出することができる.

  • 多言語化対応の不足 (翻訳されていない, るいは利用されていない文言)
  • レイアウトパフォーマンスの問題(旧layoutopt toolで検出されていたもの+α)
  • 未使用リソース
  • iconに関する問題(densityの間違いや間違ったサイズ etc...)
  • AndroidManifest関連のエラー
  • などなど他多数

Android Lintは単独動作できるコンポーネントでありCIツールとの連携が望まれている.
Lintのチェックリストは随時更新されており, Android SDK toolsとして配布されている.
検査結果をレポートすることもできる.

Android Lintの検査内容

Android SDK toolsに同梱されているlintバイナリに--showコマンドを発行すれば検査内容の一覧を確認できる.

$ lint --show

各検査項目にはPriority, Severity, Categoryが設定されている.

Priority
1~10(max:10). 問題の優先度.

Severity
Warning, Error, Fatal. 問題の重要度.

Category
Performance, Usability, Correctness, Security etc... 問題の種類.

Android Lintによる検査はリリースビルドを実行した際に自動実行される.
ここでは致命的なエラーのみを対象に検査され, 問題があった場合はビルドを中止する.

GradleのlintOptionでこれを停止することもできる.

android {
    lintOptions {
        abortOnError false
    }
}

Android Lintの実行

Android StudioであればGradleのタスクとしてlintが標準で作成されている.
GradleでAndroid Lintの挙動を制御したい場合は次のオプションを指定できる.

android {
    lintOptions {
        // set to true to turn off analysis progress reporting by lint
        quiet true
        // if true, stop the gradle build if errors are found
        abortOnError false
        // if true, only report errors
        ignoreWarnings true
        // if true, emit full/absolute paths to files with errors (true by default)
        absolutePaths true
        // if true, check all issues, including those that are off by default
        checkAllWarnings true
        // if true, treat all warnings as errors
        warningsAsErrors true
        // turn off checking the given issue ids
        disable 'TypographyFractions','TypographyQuotes'
        // turn on the given issue ids
        enable 'RtlHardcoded','RtlCompat', 'RtlEnabled'
        // check *only* the given issue ids
        check 'NewApi', 'InlinedApi'
        // if true, dont include source code lines in the error output
        noLines true
        // if true, show all locations for an error, do not truncate lists, etc.
        showAll true
        // Fallback lint configuration (default severities, etc.)
        lintConfig file("default-lint.xml")
        // if true, generate a text report of issues (false by default)
        textReport true
        // location to write the output; can be a file or 'stdout'
        textOutput 'stdout'
        // if true, generate an XML report for use by for example Jenkins
        xmlReport false
        // file to write report to (if not specified, defaults to lint-results.xml)
        xmlOutput file("lint-report.xml")
        // if true, generate an HTML report (with issue explanations, sourcecode, etc)
        htmlReport true
        // optional path to report (default will be lint-results.html in the builddir)
        htmlOutput file("lint-report.html")

        // set to true to have all release builds run lint on issues with severity=fatal
        // and abort the build (controlled by abortOnError above) if fatal issues are found
        checkReleaseBuilds true
        // Set the severity of the given issues to fatal (which means they will be
        // checked during release builds (even if the lint target is not included)
        fatal 'NewApi', 'InlineApi'
        // Set the severity of the given issues to error
        error 'Wakelock', 'TextViewEdits'
        // Set the severity of the given issues to warning
        warning 'ResourceAsColor'
        // Set the severity of the given issues to ignore (same as disabling the check)
        ignore 'TypographyQuotes'
    }
}

参考

37
33
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
33