mockito: Android instrumentation test packaging fails for mockito-android 3.5.0 with minSdk < 26
We’ve upgraded from mockito-android:3.4.6
to mockito-android:3.5.0
. I’m attempting to package up my instrumented tests by running the assembleAndroidTest
gradle task. The task fails with the following errors:
/Users/<me>/.gradle/caches/transforms-2/files-2.1/fb7959dc5bfc8ebb26ad0660efa1929e/jetified-mockito-core-3.5.0.jar: D8: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
/Users/<me>/.gradle/caches/transforms-2/files-2.1/4d4498fa5552ba637b5a9594a0871b80/jetified-objenesis-3.1.jar: D8: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
/Users/<me>/.gradle/caches/transforms-2/files-2.1/4d4498fa5552ba637b5a9594a0871b80/jetified-objenesis-3.1.jar: D8: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
and with root cause:
com.android.tools.r8.utils.b: Error: /Users/<me>/.gradle/caches/transforms-2/files-2.1/4d4498fa5552ba637b5a9594a0871b80/jetified-objenesis-3.1.jar:org/objenesis/instantiator/util/DefineClassHelper$Java8.class, java.lang.Class org.objenesis.instantiator.util.DefineClassHelper$Java8.defineClass(java.lang.String, byte[], int, int, java.lang.Class, java.lang.ClassLoader, java.security.ProtectionDomain), MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
at com.android.tools.r8.utils.y0.a(:21)
at com.android.tools.r8.utils.O.a(:51)
... 35 more
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 21
- Comments: 54 (23 by maintainers)
Commits related to this issue
- Fixes #2007 : Downgrade objenesis version for mockito-android — committed to kozaxinan/mockito by deleted user 4 years ago
- Fixes #2007 : Downgrade objenesis version for mockito-android (#2024) [ci maven-central-release] Co-authored-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com> — committed to mockito/mockito by kozaxinan 4 years ago
- Revert "Fixes #2007 : Downgrade objenesis version for mockito-android (#2024)" This reverts commit 626d4573c702625611d2024463bae606a4e8cca4. — committed to PaulKlauser/mockito by PaulKlauser 3 years ago
- Fixes #2007 : Update objenesis version to 3.2 to fix Android incompatibility — committed to PaulKlauser/mockito by PaulKlauser 3 years ago
- New: Added test suite support This required an update in mockito which was indirectly impacted by not having mavenCentral() as a repository as mentioned here https://github.com/mockito/mockito/issues... — committed to Electric-Coin-Company/zcash-android-wallet-sdk by gmale 3 years ago
@TimvdLippe there is a handier workaround for objenesis 3.x, without excluding it from
mockito-core
. In rootbuild.gradle
we can add:Here’s the stacktrace that I get when using 3.5.7:
Still getting this error with 3.5.7
We still have issues with 3.5.2. We are unable to update to new version and use
assembleAndroidTest
task.Yes these systems take a while to obtain the new information. 3.9.0 is published here: https://repo1.maven.org/maven2/org/mockito/mockito-core/3.9.0/
@TimvdLippe I played a little bit with mockito and the issue I mentioned in this comment is solved by adding in the android project’s build.gradle:
Android Gradle Plugin 3.0 and higher supports default interface methods.
The objenesis 3.x issue included in
mockito-core
mentioned here instead can be avoided by excluding objenesis frommockito-core
or any library/project depending onmockito-core
:This workaround is a little bit inconvenient IMHO, but solves the issue.
Reopening this issue, as I think it is clear by now we are going to need support from developers working in the Android ecosystem on figuring out how to resolve these issues.
@gnarea You are depending on Objenesis 3, which is incompatible with Android <26. Please downgrade to Objenesis 2 and depend on
mockito-android
. For more info, see the context in #2024Looks like the issue was introduced in objenesis 3.x (upgraded in https://github.com/mockito/mockito/pull/1998) Forcing objenesis to 2.6 makes
assembleAndroidTest
task succeed.@PaulKlauser Do you mind sending us a PR which updates the version?
Ok. I had some feedback from @mhausherr. The error is in R8. So we could ignore like this in
proguard-rules.pro
:@kozaxinan Are you certain that you are using 3.5.2 and aren’t accidentally using an older version of either Mockito or ByteBuddy? We have had confirmations from other users that 3.5.2 fixed the issue you are seeing, so it would be good to double check that you have the correct version.