在整个工程的build.gradle文件中,添加
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// add this
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
}
}
在工程的主module中(一般命名成app),应用以下插件
apply plugin: 'com.getkeepsafe.dexcount'
然后在Terminal中编译
./gradlew build
然后在结果中我们看到,会统计出当前的方法数
Total methods in XXX-release-unsigned.apk: 39518 (60.30% used)
Total fields in XXX-release-unsigned.apk: 24296 (37.07% used)