简体   繁体   English

android jetpack compose 中的可组合注释

[英]Composable annotation in android jetpack compose

I am working on a multimodule project with three modules Core , A and B .我正在开发一个包含三个模块CoreAB的多模块项目。 Both modules A and B uses Core .模块AB都使用Core There is a screen (or composable) in module B that I need to reuse in module A .模块B中有一个屏幕(或可组合),我需要在模块A中重用。 I can just move that screen to Core but I don't think this is scalable.我可以将该屏幕移至Core ,但我不认为这是可扩展的。 So I am defining an Interface in Core whose implementation would be provided by B .因此,我在Core中定义了一个Interface ,其实现将由B提供。 Then A will get that Interface through DI and use it without dealing with it's implementation.然后A将通过 DI 获取该Interface并使用它而不处理它的实现。

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

This will be implemented by B .这将由B实施。 But when I run it, it just crashes with NoSuchMethodError但是当我运行它时,它会因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.我认为这与Composable注释有关。

The solution is to enable compose(ie not only adding the compose dependencies) in all the modules that use the interface.解决方案是在所有使用该接口的模块中启用 compose(即不仅添加 compose 依赖项)。 Previously I was only enabling compose in modules A and B but not in core and that was causing the issue.以前我只在模块AB中启用组合,但在core中没有启用,这是导致问题的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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