忍者ブログ

アンドロイドのあれこれ

[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

Android Lint、アプリのパフォーマンス、開発支援のためのツール
Android LintはAndroidプロジェクトソースをスキャンして潜在的なバグ、正確性、セキュリティ、パフォーマンス、ユーザービリティ、国際化などのためにバグや最適化の改善を検出し警告してくれます。
LintはコマンドラインツールだけでなくADT(Android Development Tools)バーション16からIDEからも使えるようになりました。

以下の例はいくつかエラーの種類はLintのチェックができます

- 翻訳の未使用
- レイアウトパフォーマンスの問題
- 使われていないリソース
- 一貫性のない配列のサイズ(配列は複数の構成で定義されている場合)
- アクセシビリティや国際化の問題(ハードコード文字列、未確認コンテンツの説明など)
- アイコンの問題(行方不明の密度、重複アイコン、間違ったサイズなどなど)
- ユーザビリティの問題(テキストフィールドの入力タイプを指定されていないなど)
- AndroidManifest.xmlのエラー

lintのチェック一覧と詳細はコマンドかリンクから見ること出来ます
コマンド
$ lint --show
Android Lint Checks
http://tools.android.com/tips/lint-checks

基本的な使い方


lintコマンドで使ってみる
lint [フラグ] <プロジェクトディレクトリー>

アプリのプロジェクトにあるJavaとXMLファイルのチェックしたいとき(NFC-hansonというプロジェクト名だとする)
$ lint ~/workspace/NFC-handson

Scanning NFC-handson: ........
Scanning NFC-handson (Phase 2): ...
AndroidManifest.xml:7: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion="?" [UsesMinSdkAttributes]
<uses-sdk android:minSdkVersion="10" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AndroidManifest.xml:9: Warning: Should explicitly set android:allowBackup to true or false (it's true by default, and that can have some security implications for the application's data) [AllowBackup]
<application
^
res/values/strings.xml:4: Warning: The resource R.string.hello appears to be unused [UnusedResources]
<string name="hello">Hello World, MainActivity!</string>
~~~~~~~~~~~~
res/layout/main.xml:12: Warning: [I18N] Hardcoded string "Action :", should use @string resource [HardcodedText]
android:text="Action :" />
~~~~~~~~~~~~~~~~~~~~~~~
res/layout/main.xml:25: Warning: [I18N] Hardcoded string "ID :", should use @string resource [HardcodedText]
android:text="ID :" />
~~~~~~~~~~~~~~~~~~~
res/layout/main.xml:37: Warning: [I18N] Hardcoded string "TechList :", should use @string resource [HardcodedText]
android:text="TechList :" />
~~~~~~~~~~~~~~~~~~~~~~~~~
0 errors, 6 warnings

--checkのフラグと使って特定の問題をチェックすることができます。
たとえば、MissingPrefix(Android名前空間を使用されていないXML属性あるか検出)
$ lint --check MissingPrefix ~/workspace/NFC-handson

Scanning NFC-handson: ..

No issues found.

--disableを使って特定のファイルにチェックを無効にする
$ lint --disable UsesMinSdkAttributes,UnusedResources,HardcodedText workspace/NFC-handson/

Scanning NFC-handson: ........
Scanning NFC-handson (Phase 2): ..
AndroidManifest.xml:9: Warning: Should explicitly set android:allowBackup to true or false (it's true by default, and that can have some security implications for the application's data) [AllowBackup]
<application
^
0 errors, 1 warnings


Eclipse ADTからAndroid Lintを使う


ツールバーにあるLintは以下のようなアイコンが表示されます。
Android Lint
アイコンをクリックするとチェックしたいプロジェクトを選んで実行できます。

実行した結果はエラー説明、カテゴリー、対象ファイル名など以下のように表示されます。
Android Lint
COMMENT
NAME
TITLE
MAIL (非公開)
URL
EMOJI
Vodafone絵文字 i-mode絵文字 Ezweb絵文字
COMMENT
PASS (コメント編集に必須です)
SECRET
管理人のみ閲覧できます
 
PR
© Android Advent
powered by 忍者ツールズ / 忍者ブログ / [PR]