IllegalAccessError: Method is inaccessible to class

前端 未结 3 1818
耶瑟儿~
耶瑟儿~ 2021-02-10 02:09

I\'ve got very strange error, because it only happens after installing app from generated .apk. When I try to run the app through IDE, it works fine.



        
3条回答
  •  长发绾君心
    2021-02-10 02:51

    Make sure you've declared the method that is failing inside the same module as the calling code.

    In my case I was experiencing following error:

    java.lang.IllegalAccessError: Method 'boolean[] my.package.common.kotlin.AndroidExtensionsKt.$jacocoInit()' is inaccessible to class 'my.package.ui.first.FirstActivity$viewModel$2' (declaration of 'my.package.ui.first.FirstActivity$viewModel$2' appears in /data/app/my.package.dev-fdHNodmdXHv-b_heK4MXeA==/base.apk!classes8.dex)
        at my.package.ui.first.FirstActivity$viewModel$2.invoke(FirstActivity.kt:18)
        at my.package.ui.first.FirstActivity$viewModel$2.invoke(FirstActivity.kt:14)
        at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
        at my.package.ui.first.FirstActivity.getViewModel(Unknown Source:11)
        at my.package.ui.first.FirstActivity.onCreate(FirstActivity.kt:23)
    

    Where getViewModel() was declared in common module and FirstActivity was declared in app module:

    inline fun  FragmentActivity.getViewModel(
        factory: ViewModelProvider.Factory = ViewModelProvider.NewInstanceFactory()
    ) = ViewModelProviders.of(this, factory).get(T::class.java)
    

    After moving getViewModel() from common module to app module no issues were seen.

提交回复
热议问题