mockito-android has extremely large method count
See original GitHub issueI’ve been investigating why my test apk has hit the 65k “multidex” method limit. It seems like mockito-android
is by far the dominant contributor to method count.
To help get cleaner data, I created a brand new empty project in Android Studio 3.0-alpha3 and removed all dependencies except the following:
dependencies {
androidTestImplementation 'org.mockito:mockito-android:2.8.9'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
After this, I built the test apk using ./gradlew assembleDebugAndroidTest
and used the APK Analyzer tool in Android Studio to examine the APK. Here’s what it reports:
org.mockito
--> 2402 referenced methods
net.bytebuddy
--> 13512 referenced methods
com.android.dx
--> 4661 referenced methods
This totals to 20575 referenced methods, which is roughly 1/3 of the total allowable referenced method count for an Android test apk. Since test apks don’t support legacy multidex, if a test apk goes over the 65k method limit, they can no longer run their tests on versions of android older than API 21 (Lollipop).
For extra info, here’s the (relevant) output of ./gradlew :app:dependencies
for my sample project:
debugAndroidTestCompileClasspath - Resolved configuration for compilation for variant: debugAndroidTest
+--- org.mockito:mockito-android:2.8.9
| +--- org.mockito:mockito-core:2.8.9
| | +--- net.bytebuddy:byte-buddy:1.6.14
| | +--- net.bytebuddy:byte-buddy-agent:1.6.14
| | \--- org.objenesis:objenesis:2.5
| \--- net.bytebuddy:byte-buddy-android:1.6.5
| +--- net.bytebuddy:byte-buddy:1.6.5 -> 1.6.14
| \--- com.jakewharton.android.repackaged:dalvik-dx:1
| \--- com.jakewharton.android.repackaged:libcore-dex:2
In my real app, we are already using Proguard on our test APK, and that only strips out ~3k of the 20k methods referenced by mockito-android (so this probably isn’t a viable solution).
Is there anything we can do to reduce the method count pulled in by mockito-android
?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:15 (10 by maintainers)
Top GitHub Comments
@drewhannay Because of this, I continue to use:
See https://github.com/jaredsburrows/android-gif-example/blob/master/build.gradle#L178.
This workaround is effective only with DexMaker. It does not work with
mockito-android
that indirectly relies on Byte Buddy.