Androidentrypoint不使用AbstractComposeView

发布于 2025-02-04 13:25:47 字数 1340 浏览 5 评论 0原文

我正在使用匕首进行依赖注入。在我的AbstractComposeView中,我需要访问Compososable功能中的ViewModel。为此,我必须用@androidentrypoint注释我的AbstractComposeView,因为我的组合是AbstractComposeView的一部分(用于使用@androidentrypoint的服务中)。但是我遇到了这个错误。

error: [Hilt]
  The base class, 'androidx.compose.ui.platform.AbstractComposeView', of the @AndroidEntryPoint, 
'com.qwillio.vendi.keyboard.presentation.KeyboardView', 
contains a constructor with default parameters. 
This is currently not supported by the Gradle plugin. Either specify the 
base class as described at https://dagger.dev/hilt/gradle-setup#why-use-the-plugin 
or remove the default value declaration.
  [Hilt] Processing did not complete. See error above for details.
[Hilt]

这是我的AbstractComposeView


@AndroidEntryPoint
class KeyboardView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : AbstractComposeView(context, attrs, defStyleAttr) {

    private var keyboardActionListener: OnKeyboardActionListener? = null

    fun setOnKeyboardActionListener(keyboardActionListener: OnKeyboardActionListener) {
        this.keyboardActionListener = keyboardActionListener
    }

    @Composable
    override fun Content() {
        Vendiboard {
            keyboardActionListener?.onKeyboardAction(it)
        }
    }
}

I am using DaggerHilt for dependency injection. In my AbstractComposeView, I need to access the ViewModel in a Composable function. To do that I have to annotate my AbstractComposeView with @AndroidEntryPoint, since my Composable is part of the AbstractComposeView (which is being used in a Service with @AndroidEntryPoint). but I am getting this error.

error: [Hilt]
  The base class, 'androidx.compose.ui.platform.AbstractComposeView', of the @AndroidEntryPoint, 
'com.qwillio.vendi.keyboard.presentation.KeyboardView', 
contains a constructor with default parameters. 
This is currently not supported by the Gradle plugin. Either specify the 
base class as described at https://dagger.dev/hilt/gradle-setup#why-use-the-plugin 
or remove the default value declaration.
  [Hilt] Processing did not complete. See error above for details.
[Hilt]

This is my AbstractComposeView


@AndroidEntryPoint
class KeyboardView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : AbstractComposeView(context, attrs, defStyleAttr) {

    private var keyboardActionListener: OnKeyboardActionListener? = null

    fun setOnKeyboardActionListener(keyboardActionListener: OnKeyboardActionListener) {
        this.keyboardActionListener = keyboardActionListener
    }

    @Composable
    override fun Content() {
        Vendiboard {
            keyboardActionListener?.onKeyboardAction(it)
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文