Android 中性能优化之lint使用总结

概述

lint是随着Android SDK自带的静态代码分析工具,用来对Android工程的源文件进行检查,找出在正确性,安全,性能,可使用性,可访问性及国际化等方面可能的bugs和可优化提升的地方。其中包含一个重要的作用,就是检查项目中不用的资源文件。

lint工作流程

正对我们的项目,通过lint.xml配置lint分析的选项,执行检查后,会针对要分析的issue生成报告。
这里写图片描述

运行lint

在Android studio 中右边的菜单栏中可以找到Gradle的工具栏,展开verification,可以找到lint选项,并点击运行:
这里写图片描述
lint分析完成后,可以生成xml、html格式的报告文档。报告位置会在执行结束时,提示。文档具体指出了代码在不同方面所发现的问题,每个问题项都指出了在源文件的位置和问题描述。

设置分析的范围

lint工具提供了对代码的一系列不同方面的问题进行检查的功能。每一个问题(issue)都有它唯一的id。这些issue是分类的。
可以通过为工程配置lint.xml来指定要分析哪些方面的问题:
每个issue一个标签,可以指定它的严重性(severity)为ignore、error、warning等:
下面是一个lint.xml的示例:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <!-- Disable the given check in this project -->
    <issue id="IconMissingDensityFolder" severity="ignore" />

    <!-- Ignore the ObsoleteLayoutParam issue in the specified files -->
    <issue id="ObsoleteLayoutParam">
        <ignore path="res/layout/activation.xml" />
        <ignore path="res/layout-xlarge/activation.xml" />
    </issue>

    <!-- Ignore the UselessLeaf issue in the specified file -->
    <issue id="UselessLeaf">
        <ignore path="res/layout/main.xml" />
    </issue>

    <!-- Change the severity of hardcoded strings to "error" -->
    <issue id="HardcodedText" severity="error" />
</lint>

在xml和java文件中,也可以禁用lint检查:
● To disable lint checking for a specific Java class or method, use the @SuppressLint annotation.
● To disable lint checking for specific sections of your XML file, use the tools:ignore attribute.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值