Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android Lint 工具使用筆記

編輯:關於 Android 程式設計

在了解 android:allowBackup 屬性含義的過程中,順手發現了 Lint 的幾個實用指令,記錄於此。

查詢單一議題的說明

lint --show AllowBackup

輸出內容大致如下:

AllowBackup
-----------
Summary: Ensure that allowBackup is explicitly set in the application's manifest

Priority: 3 / 10
Severity: Warning
Category: Security

The allowBackup attribute determines if an application's data can be backed
up and restored. By default, this flag is set to true.

When this flag is set to true, application data can be backed up and restored
by the user using adb backup and adb restore. This may have security
consequences for an application. adb backup allows users who have enabled USB
debugging to copy application data off of the device. Once backed up, all
application data can be read by the user. adb restore allows creation of
application data from a source specified by the user. Following a restore,
applications should not assume that the data, file permissions, and directory
permissions were created by the application itself.

Setting allowBackup="false" opts an application out of both backup and restore.

To fix this warning, decide whether your application should support backup and
explicitly set android:allowBackup=(true|false).

More information:
https://developer.android.com/reference/android/R.attr.html#allowBackup

列出所有議題

lint --show

不帶參數直接執行 --show,會把 Lint 內建的所有檢查項目說明一次印出,很適合當作待查清單逐項掃過。

查看說明文件

lint --help

列出各項參數與用法。

小結

Lint 不只是「有紅線就修」的工具,它每條警告背後都附了完整的安全或效能說明,本身就是一份值得細讀的 Android 開發檢查指南。以上僅為拋磚引玉,更多好用的用法就留給各位自行挖掘了。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved