2014年11月29日土曜日

[Android] アプリのメソッド数を知るには

dex-method-countsというツールを使うと、APK内に含まれるメソッド数をパッケージ毎に知ることができる。

レポジトリをクローンしてきたらまずはツールのビルド。

./gradlew assemble

ビルドしたら、レポジトリのディレクトリで下記のコマンドを実行すると、指定のAPKのメソッド数をカウントしてくれる。

./dex-method-counts path/to/app.apk

アウトプットはこんな感じ

Read in 49877 method IDs.
<root>: 49877
    : 8
    android: 8768
        accessibilityservice: 6
        accounts: 4
        animation: 2
        app: 308
        bluetooth: 2
        content: 260
            pm: 24
            res: 51
            ...
        support: 6302
            annotation: 3
            v4: 6299
                accessibilityservice: 41
                app: 1371
        ...
    butterknife: 161
        internal: 89
    com: 30662
        bumptech: 2113
            glide: 2113
                ...
        google: 22969
            ...
Overall method count: 49877

ご覧のように、パッケージごとに細かくメソッド数を算出してくれる。

下記のようなエラー(いわゆる65K問題)が出てしまった時、削るライブラリの候補を考えるのに便利。

trouble writing output:
Too many field references: 131000; max is 65536.
You may try using --multi-dex option.

0 件のコメント:

コメントを投稿