Android效能最佳化之LINT使用總結
實話啊,重視lint吧。 lint工具對於android應用開發中記憶體最佳化、效能最佳化、代碼規範等有灰常灰常大的協助作用。每個模組開發完成後,lint一下,有意想不到的收穫。
介紹: 靜態程式碼分析工具,無需運行,無需測試案例 掃描整個項目,分析以下潛在的問題,分類指出問題描述、問題位置,並提供合理的修改建議(這是才是關鍵啊,不管有木有大問題,看看這些問題及描述,也能過把癮啊): ==================================== correctness 正確性 security 安全性 performance 效能 usability 可用性 accessibility 可達性 internationalization 國際化 ====================================
1)效能
布局效能(以前是 layoutopt工具,可以解決無用布局、嵌套太多、布局太多、overdraw)
其他效能(如:draw/layout 時進行對象的聲明等)
2)未使用到資源、資源缺少(不同資源的適配)
3)有更高效能的資源替換 ---- eg:SparseBooleanArray SparseIntArray
4)國際化問題(寫入程式碼)
5)表徵圖的問題(重複的表徵圖,錯誤的大小)
6)可用性問題(如不指定的文字欄位的輸入型)
7)manifest檔案的錯誤 -- 未註冊activity service等等
8)記憶體泄露 --- 如:handle的不當使用 。
9)占記憶體的資源及時回收 --- 如:TypedArray未回收資源等
======================================
常用命令: lint命令位於sdk/tools/下邊,在tools目錄下,或者配置sdk環境變數(配置方法:http://blog.csdn.net/rflyee/article/details/8973529) lint project # 掃描指定的項目 lint --check correctness --html report.html project # 掃描指定項目,並產生html格式的報告 lint --help #查看協助
使用方法: 1. 命令。如上所述 2. eclipse (1) 右鍵 -- Android Tools > Run Lint: Check for Common Errors.
(2) Window > Show View > Other > Android > Lint Warnings
配置
部分禁用方式: 1. xml tools:ignore 注意:namespace xmlns:tools=http://schemas.android.com/tools
tools:ignore=UnusedResources
tools:ignore=NewApi,StringFormatInvalid
tools:ignore=all
2. java @SuppressLint
@SuppressLint(NewApi)
@SuppressLint(all)