kotlin, coroutines, NoSuchMethodError when calling overriden suspended function from other module

泪湿孤枕 提交于 2020-01-04 02:38:10

问题


Whenever I try to execute overrided suspend method which is defined in other module it fails with NoSuchMethodError (see more details below).

Here what I am doing exactly:

I have two modules app and lib.

lib here I have an interface (OtherModuleInterface) with suspend method (test).

app here I have defined implementation (OtherModuleImpl) of that interface.

If I call it like this:

 val myOtherModuleObject : OtherModuleImpl = OtherModuleImpl()
    runBlocking { myOtherModuleObject.test() }

Then it works fine.

If I use OtherModuleInterface as type of value:

val myOtherModuleObject : OtherModuleInterface = OtherModuleImpl()
runBlocking { myOtherModuleObject.test() }

It fails with exception:

java.lang.NoSuchMethodError: com.example.lib.OtherModuleInterface.test(Lkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object.

If I put both interface and implementation in the same module it works fine:

val mySameModuleObject : SameModuleInterface = SameModuleImpl()
    runBlocking { mySameModuleObject.test() }

You can check out code here to see whole project configuration: https://github.com/rjuszczyk/kotlin-coroutines-problem and run ExampleUnitTest to see the error.

来源:https://stackoverflow.com/questions/52037520/kotlin-coroutines-nosuchmethoderror-when-calling-overriden-suspended-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!