Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 377
Clyde Avatar asked May 31 '18 22:05

Clyde


2 Answers

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

like image 76
Hatzen Avatar answered Oct 04 '22 04:10

Hatzen


One approach would be to set your min api to 26, to avoid the error and build the apk, and then inspect the bytecode of the app (dexdump, baksmali, etc.) to find any usages of the MethodHandle class.

like image 43
JesusFreke Avatar answered Oct 04 '22 02:10

JesusFreke