Recently I came across this weird behavior: Overall my app works and compiles as normal, but when I try to instantiate a fragment, which contains code which passes a function reference to a extension inline function, which takes a crossinline lambda my app throws a java.lang.VerifyError.
First I didn't know the exact source of the problem, so I did follow some answers on Stack Overflow and cleared the cache and deleted the build folders, it didn't help. So, I tried to isolate the problem further and commented out my code until I found the exact line which caused the error:
overview_button_details.click (viewModel::startDetailGroupActivity)
Implementation of click:
[1] inline fun View.click( crossinline listener: () -> Unit) = setOnClickListener { _ -> listener() }
This combination didn't work but I found out that the following combinations work
Either using:
overview_button_details.click { viewModel.startDetailGroupActivity() }
with [1]. Or changing the function to not be a inline function and not taking a crossinline lambda:
fun View.click( listener: () -> Unit) = setOnClickListener { _ -> listener() }
I am confused because the compiler and android studio didn't tell me anything that this function [1] could cause an error, neither the stack trace helped me:
java.lang.VerifyError: Verifier rejected class ________.NewFragment due to bad method void _______.NewFragment.onViewCreated(android.view.View, android.os.Bundle) (declaration of '_______.NewFragment' appears in /data/app/______-1/split_lib_slice_4_apk.apk)
at ________.main.MainViewModel.navigateOverview(MainViewModel.kt:93)
at ________.main.MainActivity$mOnNavigationItemSelectedListener$1.onNavigationItemSelected(MainActivity.kt:71)
at android.support.design.widget.BottomNavigationView$1.onMenuItemSelected(BottomNavigationView.java:182)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
at android.support.design.internal.BottomNavigationMenuView$1.onClick(BottomNavigationMenuView.java:95)
at android.view.View.performClick(View.java:5233)
at android.view.View$PerformClick.run(View.java:21211)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I have a lack of experience with this, so I wonder if it's this a bug or if it's it my fault? If so, where is the mistake?