Android效能最佳化之LINT使用總結

來源:互聯網
上載者:User

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)
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.