Skip to content

Dexcount Gradle Plugin

A Gradle plugin to report the number of method references in your APK, AAR, or java module on every build.

This helps you keep tabs on the growth of your app, with an eye to staying under the 65,536 method-reference limit, and avoiding the headache of eliminating methods or enabling multidex.



plugins {
    // make sure to apply an Android plugin *before* dexcount
    id "com.getkeepsafe.dexcount"

Or, if you prefer the legacy “apply plugin” syntax:

// in build.gradle
buildscript {
    repositories {

    dependencies {
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:4.0.0'

// in app/build.gradle
// make sure this line comes *after* you apply the Android plugin
apply plugin: 'com.getkeepsafe.dexcount'


When applied, dexcount-gradle-plugin will create one task per Android variant that you can execute to produce method-count reports. The tasks are named according the variant, in the format “count${variant}DexMethods”. In a typical app, that means there will be tasks named countDebugDexMethods and countReleaseDexMethods.

Historically, these counting tasks were run by default on every build; this continues to be true for projects using versions of Android Gradle Plugin from 3.4.0 up until 4.1.0. Beginning with 4.1.0, this is no longer the case, and method counts must be manually requested.

Here’s how to build and count an APK:

# Build an APK and count its method references
./gradlew :app:countDebugDexMethods

# Build an AAR and produce an approximate method count
./gradlew :lib:countDebugDexMethods

# Build an App Bundle (.aab) and count its method references
# (requires AGP 4.1.0 and above)
./gradlew :app:countDebugBundleDexMethods

Sample output

> ./gradlew assembleDebug

:app:preDexDebug UP-TO-DATE
Total methods in MyApp-debug.apk: 58930 (89.92% used)
Total fields in MyApp-debug.apk:  27507 (41.97% used)
Methods remaining in MyApp-debug.apk: 6605
Fields remaining in MyApp-debug.apk:  38028


Total time: 33.017 secs

Detailed method counts

By default, a breakdown of method references by package and class will be written to a file under ${buildDir}/outputs/dexcount/${variant}/.

For example, an excerpt from our own app (in app/build/outputs/dexcount/debug/debug.txt):

methods  fields   package/class name
5037     1103
29       1
57       16
931      405
87       31
139      12
116      11
74       9
74       9
194      35
11       0
156      26

Snapshot Builds

We host snapshots in the Sonatype OSS repo. They are updated on each commit. As snapshots, they are inherently unstable - use at your own risk! To use them, add the Sonatype Snapshot repo to your repositories:

buildscript {
  repositories {
    // other repos should come first
    maven { url '' }

  dependencies {
    classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:4.0.1-SNAPSHOT'