Lint support(Lint支持)

Lint支持,译者注:Lint是一个可以检查Android项目中存在的问题的工具

从0.7.0版本开始,你可以为项目中一个特定的Variant(变种)版本运行lint,也可以为所有Variant版本都运行lint。它将会生成一个报告描述哪一个Variant版本中存在着问题。

你可以通过以下lint选项配置lint。通常情况下你只需要配置其中一部分,以下列出了所有可使用的选项:

  1. android {
  2. lintOptions {
  3. // set to true to turn off analysis progress reporting by lint
  4. quiet true
  5. // if true, stop the gradle build if errors are found
  6. abortOnError false
  7. // if true, only report errors
  8. ignoreWarnings true
  9. // if true, emit full/absolute paths to files with errors (true by default)
  10. //absolutePaths true
  11. // if true, check all issues, including those that are off by default
  12. checkAllWarnings true
  13. // if true, treat all warnings as errors
  14. warningsAsErrors true
  15. // turn off checking the given issue id's
  16. disable 'TypographyFractions','TypographyQuotes'
  17. // turn on the given issue id's
  18. enable 'RtlHardcoded','RtlCompat', 'RtlEnabled'
  19. // check *only* the given issue id's
  20. check 'NewApi', 'InlinedApi'
  21. // if true, don't include source code lines in the error output
  22. noLines true
  23. // if true, show all locations for an error, do not truncate lists, etc.
  24. showAll true
  25. // Fallback lint configuration (default severities, etc.)
  26. lintConfig file("default-lint.xml")
  27. // if true, generate a text report of issues (false by default)
  28. textReport true
  29. // location to write the output; can be a file or 'stdout'
  30. textOutput 'stdout'
  31. // if true, generate an XML report for use by for example Jenkins
  32. xmlReport false
  33. // file to write report to (if not specified, defaults to lint-results.xml)
  34. xmlOutput file("lint-report.xml")
  35. // if true, generate an HTML report (with issue explanations, sourcecode, etc)
  36. htmlReport true
  37. // optional path to report (default will be lint-results.html in the builddir)
  38. htmlOutput file("lint-report.html")
  39. // set to true to have all release builds run lint on issues with severity=fatal
  40. // and abort the build (controlled by abortOnError above) if fatal issues are found
  41. checkReleaseBuilds true
  42. // Set the severity of the given issues to fatal (which means they will be
  43. // checked during release builds (even if the lint target is not included)
  44. fatal 'NewApi', 'InlineApi'
  45. // Set the severity of the given issues to error
  46. error 'Wakelock', 'TextViewEdits'
  47. // Set the severity of the given issues to warning
  48. warning 'ResourceAsColor'
  49. // Set the severity of the given issues to ignore (same as disabling the check)
  50. ignore 'TypographyQuotes'
  51. }
  52. }