问题
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