Command-line tool to count per-package methods in Android .dex files

Overview

dex-method-counts

Simple tool to output per-package method counts in an Android DEX executable grouped by package, to aid in getting under the 65,536 referenced method limit. More details are in this blog post.

To run it with Ant:

$ ant jar
$ ./dex-method-counts path/to/App.apk # or .zip or .dex or directory

or with Gradle:

$ ./gradlew assemble
$ ./dex-method-counts path/to/App.apk # or .zip or .dex or directory

on Windows:

$ gradlew assemble
$ dex-method-counts.bat path\to\App.apk

You'll see output of the form:

Read in 65490 method IDs.
<root>: 65490
    : 3
    android: 6837
        accessibilityservice: 6
        bluetooth: 2
        content: 248
            pm: 22
            res: 45
        ...
    com: 53881
        adjust: 283
            sdk: 283
        codebutler: 65
            android_websockets: 65
        ...
    Overall method count: 65490

Supported options are:

  • --count-fields: Provide the field count instead of the method count.
  • --include-classes: Treat classes as packages and provide per-class method counts. One use-case is for protocol buffers where all generated code in a package ends up in a single class.
  • --package-filter=...: Only consider methods whose fully qualified name starts with this prefix.
  • --max-depth=...: Limit how far into package paths (or inner classes, with --include-classes) counts should be reported for.
  • --filter=[all|defined_only|referenced_only]: Whether to count all methods (the default), just those defined in the input file, or just those that are referenced in it. Note that referenced methods count against the 64K method limit too.
  • --output-style=[flat|tree]: Print the output as a list or as an indented tree.

The DEX file parsing is based on the dexdeps tool from the Android source tree.

Comments
  • Adds a new flag —output_style which defaults to TREE (the current

    Adds a new flag —output_style which defaults to TREE (the current

    implementation), but supports FLAT. In FLAT output mode, the output is dumped in a format that resembles that of the dex tool itself when you exceed the method limit (flat list of packages proceeded by their package list).

    opened by brianduff 7
  • Add Windows instructions

    Add Windows instructions

    Windows doesn't support the runfile you provided. You can make a .bat file, or provide the different code for Windows:

    java -jar [path-to-generated-jar (./build/jar/....)] [filename to inspect]

    opened by FWest98 5
  • MultiDex / ART support

    MultiDex / ART support

    It doesn't appear that the script supports builds that result in multiple dex files, where classes are segmented into a primary dex file and additional dex files. The script reports only 22K methods, which I believe to be merely the methods from the primary dex (mostly our own application minus libraries.)

    The Android tool chain will generate multiple DEX files when your minSdkLevel is Lollipop / 21 since that is how ART deals with library code (one dex per dependency), and also when you have the multidex switch enabled.

    opened by mttkay 4
  • Add a new --output_style flag to support FLAT mode

    Add a new --output_style flag to support FLAT mode

    The default style still is TREE mode, but a new FLAT mode is added in which the output is dumped in a format that resembles that of the dex tool itself when you exceed the method limit (flat list of packages proceeded by their package list).

    Original PR #8 by @brianduff.

    opened by sschuberth 3
  • Support

    Support "quiet" or "simple" mode

    Would be great to have a switch that enables a mode which prints only the total method count. I've added this functionality in my fork but it constitutes some rather reaching changes to the code base that I'm not sure fit the pattern you're currently using.

    opened by dambrisco 2
  • Avoid duplication download gradle file

    Avoid duplication download gradle file

    If you have download gradle file in AndroidStudio, then you can replace "distributionUrl=https://services.gradle.org/distributions/gradle-2.4-bin.zip" in gradle/wrapper/gradle-wrapper.properties by "distributionUrl=https://services.gradle.org/distributions/gradle-2.4-all.zip" then the gradle file would not need to download again.

    This tip may be useful to the developers in counties which has limited access to gradle.org

    opened by callmepeanut 2
  • directories support added

    directories support added

    Added the ability to enter a directory as input parameter. Directory may contain any supported file types. Script is now printing overall method count from all files after evaluation.

    opened by dmide 2
  • 单独下载 matrix-apk-canary-0.4.10.jar 失败

    单独下载 matrix-apk-canary-0.4.10.jar 失败

    在 https://github.com/Tencent/matrix#matrix_cn 页面单独下载 matrix-apk-canary-0.4.10.jar 失败 浏览器提示:

    载入页面时与 d29vzk4ow07wi7.cloudfront.net 的连接中断。

    由于不能验证所收到的数据是否可信,无法显示您想要查看的页面。
    建议向此网站的管理员反馈这个问题。
    
    opened by rootiny 1
  • Methods of Android package also included in my JAR for dexcount

    Methods of Android package also included in my JAR for dexcount

    Hi i have a JAR which is a library that i have developed for Android devices. I convert the JAR into dex and then run the script. But in my JAR, why are the method counts for android and JAVA packages are involved? These methods are native android and JAVA methods and they don't ship into my JAR. So why are these included for the dex count?

    android: 650
            animation: 10
            app: 47
            content: 93
                pm: 11
                res: 4
            database: 18
                sqlite: 8
            graphics: 58
                drawable: 8
            location: 20
            media: 20
            net: 20
                wifi: 8
            os: 38
            provider: 3
            support: 23
                v4: 15
                    view: 15
                v7: 8
                    widget: 8
            telephony: 41
                cdma: 3
                gsm: 3
            text: 1
            util: 15
            view: 101
                accessibility: 2
                animation: 10
            webkit: 50
            widget: 92
       .........
       .........
    
        java: 381
            io: 36
            lang: 145
                ref: 3
                reflect: 8
            math: 1
            net: 25
            nio: 4
            security: 9
                spec: 1
            text: 5
            util: 156
                concurrent: 37
                    atomic: 8
                zip: 1
        javax: 17
            crypto: 14
                spec: 3
            xml: 3
                parsers: 3
        org: 61
            json: 50
            w3c: 10
                dom: 10
            xml: 1
                sax: 1
    

    Overall method count: 6163

    opened by rahulrj 1
  • Allow passing of multiple arguments.

    Allow passing of multiple arguments.

    By using %1 it was impossible to use arguments with the bat file. A call like:

    dex-method-counts.bat --output-style=flat my.apk
    

    would result in

    Exception in thread "main" java.lang.IllegalArgumentException: No enum constant info.persistent.dex.DexCount.OutputStyle.--OUTPUT-STYLE
    

    This change to the bat file passes all arguments to the java call, allowing the above example to work.

    opened by FodderMK 1
  • #38 publish helper

    #38 publish helper

    mostly gradle scripts to help you publish to maven central.

    From here, you'll need to create a gpg key, and a sonatype oss account

    then run the commands in the readme file.

    opened by spyhunter99 1
  • Update DEX file magic

    Update DEX file magic

    https://github.com/mihaip/dex-method-counts/blob/master/src/com/android/dexdeps/DexData.java#L571-L572

    static class HeaderItem {
      public static final byte[] DEX_FILE_MAGIC = { 0x64, 0x65, 0x78, 0x0a, 0x30, 0x33 }; // , 0x??, 0x00 };
    }
    
    private static boolean verifyMagic(byte[] magic) {
      return Arrays.equals(Arrays.copyOfRange(magic,0,HeaderItem.DEX_FILE_MAGIC.length), HeaderItem.DEX_FILE_MAGIC)
      && magic[HeaderItem.DEX_FILE_MAGIC.length] >= 0x30
      && magic[HeaderItem.DEX_FILE_MAGIC.length+1] == 0x00;
    }
    
    opened by neomafo88 1
  • Counting in decompiled APK

    Counting in decompiled APK

    Can you make it possible to count inside decompiled APK, so I can easly see if i have reached the limit or not when working with smali without having to recompile?

    opened by VanHoevenTR 0
  • Update Gradle wrapper to 5.6.4

    Update Gradle wrapper to 5.6.4

    This updates the Gradle wrapper to the latest version 5.6.4.

    Welcome to Gradle 5.6.4!
    
    Here are the highlights of this release:
     - Incremental Groovy compilation
     - Groovy compile avoidance
     - Test fixtures for Java projects
     - Manage plugin versions via settings script
    
    For more details see https://docs.gradle.org/5.6.4/release-notes.html
    

    Please NO GitHub rebase/squash merges. The changes in this pull request are broken up into meaningful, atomic commits, and my branch should already be up-to-date with the latest target branch. If it isn't, or if you'd like me to combine some or all of the commits, please let me know, and I will make the necessary updates as soon as possible. Thank you!

    opened by friederbluemle 10
  • fix that default pkg's method count is at most 1

    fix that default pkg's method count is at most 1

    Bug description: No matter how many default package methods there are, the printed result is always 1 for default package methods count. Explanation: The name in line 49 may be "", which means corresponding method is from default package. For the default package methods, code runs into else branch since no child has name "". Therefore, for every default package method, a new Node is created in line 53. For non-first default package method, the newly created Node will always replace the former Node in line 59, and get its count equals 1 in line 63. Overall, method count of default package is always at most 1. I added an else if branch, which avoids making new Node if we already has a Node when the coming method is a default package method.

    opened by Tao93 0
  • compare method counts between inputs and a couple of fixes

    compare method counts between inputs and a couple of fixes

    There's two fixes related to print output and gitignore. But more importantly I've added the ability to compare method counts between the supplied inputs, which prints the difference between the second and first input next to the counts for the second.

    opened by martino2k6 0
Owner
Mihai Parparita
Engineer at Quip
Mihai Parparita
A command line tool that helps bulk manage resources in an Android project

Resource Mover ResourceMover is a command line tool that helps bulk manage resources in an Android project. Installation Clone project Build CLI jar u

Shopify 4 Dec 24, 2021
:inbox_tray: [Android Library] Hunt down all package information

Android library to hunt down package information. The library is built for simplicity and approachability. It not only eliminates most boilerplate cod

Nishant Srivastava 141 Nov 17, 2022
Modulearchive - Improve the efficiency of compiling Android.Package module as AAR and cache it

ModuleArchive 一个可以提升Android编译效率的Gradle小插件 在多module工程下,大多数情况我们若干子module是不会变动的 但是在当前gradle版本偶尔会触发联动编译进而影响编译效率。 本插件会自动缓存编译后的子模块生产物(xxx.aar),且会自动替换依赖为aar依

JackFan 3 Feb 11, 2022
Library that makes it possible to read, edit and write CSV files

AdaptiveTableLayout Welcome the new CSV Library AdaptiveTableLayout for Android by Cleveroad Pay your attention to our new library that makes it possi

Cleveroad 1.9k Jan 6, 2023
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022
A simple utility to remove unused resources in your Android app to lower the size of the APK. It's based on the Android lint tool output.

android-resource-remover android-resource-remover is utility that removes unused resources reported by Android Lint from your project. The goal is to

Keepsafe 1.3k Dec 16, 2022
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022
A super fast build tool for Android, an alternative to Instant Run

Freeline Freeline is a super fast build tool for Android and an alternative to Instant Run. Caching reusable class files and resource indices, it enab

Alibaba 5.5k Jan 2, 2023
Android Material Design Theme UI and Tool Library. Support: 4.0.3~O

GitHub OSChina 中文 English Genius-Android Genius-Android: by Material Design style and some commonly used packages. Starting in 2015, The divided into

Qiujuer 2.3k Dec 27, 2022
Android Merge Tool

AMT The Android Merge Tool (AMT) does what the name suggests: it merges arbitrary Android apps into a single merged app. As input it takes a number of

FoelliX 23 Nov 8, 2022
Android Studio's Vector Drawable conversion tool in convenient packaging.

Vector Drawable Tool This repository is simply a repackaging of the vector drawable tool from the Android Studio source code. The included Gradle file

Ryan Harter 55 Sep 26, 2022
Localization tool for Android Studio Projects

Android Strings Resource Language Diff tool In the event any additional languages are intended to be supported by your app. You can use this strings-d

Braxton Nunnally 1 Mar 24, 2022
A surgical debugging tool to uncover the layers under your app.

Scalpel DEPRECATED! Android Studio 4.0's layout inspector now includes a live-updating 3D view. Use it! A surgical debugging tool to uncover the layer

Jake Wharton 2.8k Jan 3, 2023
Tool for create complex morphing animations using VectorDrawables (allows morphing between any pair of SVG images)

VectAlign VectAlign (a.k.a. VectorDrawableAlign) is a developer's tool which automagically aligns two VectorDrawable "pathData" strings (or SVG images

Stefano Bonetta 2k Dec 29, 2022
GPS tracking tool for OpenStreetMap

OSMTracker for Android™ official source code repository is https://github.com/labexp/osmtracker-android. For more information about the project, docum

Laboratorio Experimental (ITCR @ SIUA) 455 Dec 25, 2022
GPS tracking tool for OpenStreetMap

OSMTracker for Android™ official source code repository is https://github.com/labexp/osmtracker-android. For more information about the project, docum

Laboratorio Experimental (ITCR @ SIUA) 455 Dec 25, 2022
Custom content tool for The Ponies.

PoneCrafter A sneak preview of the custom content tool for The Ponies. The Ponies is a work in progress life simulator game. The game itself has not b

The Ponies 8 Feb 13, 2022