7

My project's gradle file is as below.

android {
    compileSdkVersion 23
    buildToolsVersion "25.0.1"

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }
    }
}

I can see DexIndexOverflowException when "Generate Signed APK" in Android Studio.

Error:Execution failed for task ':MyProject:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: 
com.android.ide.common.process.ProcessException: 
java.util.concurrent.ExecutionException: 
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

I already know this error and read the document(https://developer.android.com/studio/build/multidex.html).
Just I want to check How many dex has exceeded.

For example:

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

Please find a solution.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
SaeHyun Kim
  • 475
  • 2
  • 8
  • 26
  • If your build fails, there is no APK to count. It's ironic that a method-limit-exceeded failure will prevent the method count from happening. – sivaBE35 Jan 20 '17 at 08:15

5 Answers5

7

Android Studio has an APK analyzer that shows this information, no gradle plugins required.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
1

use this plugin to get the number of method references in your APK on every build.

dexcount

sivaBE35
  • 1,876
  • 18
  • 23
1

Take a look at this. I was searching for the same and found my answer here. Basicly, you have to generate the APK of your project and then go to Build->Analyze APK and at the rasults click on classes.dex, then, below you will see exactly how many methods are defined and referenced by the project.

Manolee
  • 21
  • 1
  • 4
0

Android studio has a plugin called Android Methods Count which will show the number of methods for each of your dependencies.

There's also a cli tool available with more options at https://github.com/mihaip/dex-method-counts

ashkhn
  • 1,642
  • 1
  • 13
  • 18
  • 1
    Can I see dex count when build failed? – SaeHyun Kim Jan 20 '17 at 08:09
  • `Android Methods Count` will display the methods count for each of your dependencies when you hover over them inside your `build,gradle` . The other tool needs your apk file to do so you'll need to remove some dependencies and then check with that. Also check your Proguard settings to see if any unused methods can be removed – ashkhn Jan 20 '17 at 08:13
0

I modified dx.jar source to show method count.

https://github.com/b1uec0in/dx

Output sample

string ID count: 91,857
type ID count: 12,636
proto ID count: 18,417
field ID count: 72,011 (max:65535 +6476)
method ID count: 81,181 (max:65535 +15646)

replace your dx.jar with this dx.jar.

UnknownStack
  • 1,350
  • 16
  • 18