简体   繁体   中英

Composable annotation in android jetpack compose

I am working on a multimodule project with three modules Core , A and B . Both modules A and B uses Core . There is a screen (or composable) in module B that I need to reuse in module A . I can just move that screen to Core but I don't think this is scalable. So I am defining an Interface in Core whose implementation would be provided by B . Then A will get that Interface through DI and use it without dealing with it's implementation.

interface NotificationLayout {
    @Composable
    fun NotificationLayoutStatusState(
        modifier: Modifier,
    )
}

This will be implemented by B . But when I run it, it just crashes with NoSuchMethodError

java.lang.NoSuchMethodError: No interface method NotificationLayoutStatusState(Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;I)V

Can anyone please help me. I think this has to do with the Composable annotation.

The solution is to enable compose(ie not only adding the compose dependencies) in all the modules that use the interface. Previously I was only enabling compose in modules A and B but not in core and that was causing the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM