How to find cause of error when dexing: MethodHandle.invoke and MethodHandle.invokeExact

Clyde picture Clyde · Jun 1, 2018 · Viewed 8.6k times · Source

I have a project that has started throwing this error when building in Android Studio or Gradle:

com.android.tools.r8.ApiLevelException: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)

Now I assume that it's related to use of Java 8 features, perhaps a lambda, but the error message gives no clue as to where the problem lies - it could be my code or it could be a library.

What's the best way to find out where the offending code is? It's a reasonably large app with several modules and quite a few libraries.

Answer

Hatzen picture Hatzen · Mar 27, 2020

In my case i tried to mock something via mockk in an instrumentation test running Api Version 26 or higher, removing the dependency was my only solution as long as following issue is not resolved: https://github.com/mockk/mockk/issues/281


Update: It seems that the issue got resolved and using mockk version 1.10.0 will resolve this issue